注意:并非原创,此方法原来在哪里看见过,不记得出处了,由于遇到这个需求,特此记录一下
官方iOS10不能跳转系统设置页面,iOS提供了一套未公开方法。但审核是一个问题,不过我们可以想办法绕过审核
- (IBAction)tapAction:(id)sender {
NSString * defaultSetter= [self getSetter];
NSString * settingMethod = [self getSetterMethod];
NSURL*url=[NSURL URLWithString:@"Prefs:root=TETHERING"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultSetter)] performSelector:NSSelectorFromString(settingMethod) withObject:url withObject:nil];
}
利用ASCII值进行拼装组合方法来绕过审核。
-(NSString *)getSetter{
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 *)getSetterMethod{
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;
}
注意 :在plist设置url Scheme ,iOS10里边的Prefs的P要大写,不能小写p