关于iOS 10,跳转系统设置问题

发布于 2022-09-04 07:48:29 字数 1710 浏览 19 评论 0

iOS 10 更新以后,发现以前跳转系统应用的方法无效了。(已解决:参考 https://github.com/sushushu/i...

-(void)toWIFI {
    
    NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];

    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        [[UIApplication sharedApplication] openURL:url]; // iOS 9 的跳转
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];// iOS 10 的跳转方式
    }
}

    

iOS 9的时候[[UIApplication sharedApplication] openURL:url]; 这个方法正常跳转,到了iOS 10的时候这个方法就不能用了。官方API如下:

- (BOOL)openURL:(NSURL*)url NS_DEPRECATED_IOS(2_0, 10_0, "Please use openURL:options:completionHandler: instead") NS_EXTENSION_UNAVAILABLE_IOS("");
- (BOOL)canOpenURL:(NSURL *)url NS_AVAILABLE_IOS(3_0);
    // Options are specified in the section below for openURL options. An empty options dictionary will result in the same
    // behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather
    // than returning a result.
    // The completion handler is called on the main queue.
    - (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");  

请问我该如何使用新的API
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS(""); 或者说这个options我该传什么进去(经测试,传空字典是没有用的)?

万分感谢。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

牛↙奶布丁 2022-09-11 07:48:30

麻烦问下楼主,如何解决的?

墨小墨 2022-09-11 07:48:29

放弃吧,iOS 10 不允许跳转到任何系统设置。

伴我心暖 2022-09-11 07:48:29

针对iOS10不跳转问题,其实iOS提供了一套未公开方法。但审核是一个问题,不过我们可以想办法绕过审核。

NSString * defaultWork = [self getDefaultWork];
NSString * bluetoothMethod = [self getBluetoothMethod];        
NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace  performSelector:NSSelectorFromString(defaultWork)]   performSelector:NSSelectorFromString(bluetoothMethod) withObject:url     withObject:nil];

利用ASCII值进行拼装组合方法。这样可绕过审核。

-(NSString *) getDefaultWork{
   NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];
    NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
return method;
}

-(NSString *) getBluetoothMethod{
    NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
    NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
    NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
    NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
    NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];
return method;
}

上面是进入蓝牙界面的方法。也可以有其他的页面可以跳转。设置页面是@"@"Prefs:root=TETHERING",wifi是@"Prefs:root=WIFI"。注意Prefs的P是大写。
这么写也有弊端,如果苹果的未公开方法一旦修改。我们必须重新进行修改。

乞讨 2022-09-11 07:48:29

你没有设置应用的url Scheme吧

图片描述

半暖夏伤 2022-09-11 07:48:29

在ios10里面这样写,群里一个大神教的
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

对不⑦ 2022-09-11 07:48:29

兄弟 我知道了 哈哈 我刚刚找到解决方法

pragma mark -- openURL options --

// Option for openURL:options:CompletionHandler: only open URL if it is a valid universal link with an application configured to open it
// If there is no application configured, or the user disabled using it to open the link, completion handler called with NO
UIKIT_EXTERN NSString *const UIApplicationOpenURLOptionUniversalLinksOnly NS_AVAILABLE_IOS(10_0);

隱形的亼 2022-09-11 07:48:29

[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@""} completionHandler:nil ];

您的好友蓝忘机已上羡 2022-09-11 07:48:29

ios之后,苹果系统不给公开使用跳转设置了。如果你的app是要提交Apple store审核的,建议不要使用以下未公开的api,不然会审核不通过。最后自讨苦吃,还要删代码,还要浪费时间等待审核。

小糖芽 2022-09-11 07:48:29
    NSURL *url = [NSURL URLWithString:@"prefs:root=com.testproject.testname"];
        [[UIApplication sharedApplication]openURL:url

];
这样就OK吧  里面写你的项目名字 可以跳去
小姐丶请自重 2022-09-11 07:48:29

遇到相同的问题,请问您解决了吗?

甜扑 2022-09-11 07:48:29

请问您解决了吗

梦断已成空 2022-09-11 07:48:29

NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=MICROPHONE"];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文