objective-c - iOS开发,如何跳转到系统设置页?iOS10

 苦--但是依然love着你 发布于 2022-10-26 14:39

使用[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]]在iOS9和8上可以成功跳转,但是在iOS10上无效。

4 个回答
  • 针对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{
    SData *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是大写。这么写也有弊端,如果苹果的未公开方法一旦修改。我们必须重新进行修改。

    参考我的另外一个回答:https://segmentfault.com/q/10...

    2022-11-12 01:39 回答
  • 在ios10中跳转到具体的比如wifi,位置开关等具体的设置界面都已经被列为私有的API了,不允许使用;ios10只能跳转到相应的APP设置界面:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

    2022-11-12 01:39 回答
  • 把prefs: 换成Prefs: 就可以了

    2022-11-12 01:39 回答
  • iOS10的URL换掉了,具体参照 https://github.com/cyanzhong/...
    不过这个只在Widge里有效,App中无效。
    用其他办法也可以做到跳转,不过因为是私有API会通不过审核。

    参考:http://stackoverflow.com/ques...

    2022-11-12 01:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有