关于iOS 10,跳转系统设置问题
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我该传什么进去(经测试,传空字典是没有用的)?
万分感谢。
回答:
放弃吧,iOS 10 不允许跳转到任何系统设置。
回答:
针对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是大写。
这么写也有弊端,如果苹果的未公开方法一旦修改。我们必须重新进行修改。
回答:
你没有设置应用的url Scheme吧
回答:
在ios10里面这样写,群里一个大神教的
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
回答:
兄弟 我知道了 哈哈 我刚刚找到解决方法
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);
回答:
[[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@""} completionHandler:nil ];
回答:
ios之后,苹果系统不给公开使用跳转设置了。如果你的app是要提交Apple store审核的,建议不要使用以下未公开的api,不然会审核不通过。最后自讨苦吃,还要删代码,还要浪费时间等待审核。
回答:
NSURL *url = [NSURL URLWithString:@"prefs:root=com.testproject.testname"]; [[UIApplication sharedApplication]openURL:url
];
这样就OK吧 里面写你的项目名字 可以跳去
回答:
遇到相同的问题,请问您解决了吗?
回答:
请问您解决了吗
回答:
NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=MICROPHONE"];
回答:
麻烦问下楼主,如何解决的?
以上是 关于iOS 10,跳转系统设置问题 的全部内容, 来源链接: utcz.com/p/184984.html