search

Home  >  Q&A  >  body text

ios10 - 关于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我该传什么进去(经测试,传空字典是没有用的)?

万分感谢。

天蓬老师天蓬老师2771 days ago443

reply all(10)I'll reply

  • PHPz

    PHPz2017-04-18 09:50:49

    Give up, iOS 10 does not allow jumping to any system settings.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:50:49

    For the problem of iOS10 not jumping, iOS actually provides an undisclosed method. But auditing is a problem, but we can find ways to bypass it.

    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];
    

    Use ASCII values ​​for assembly and combination method. This bypasses review.

    -(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;
    }
    

    The above is how to enter the Bluetooth interface. There can also be other pages to jump to. The setting page is @"@"Prefs:root=TETHERING", and the wifi is @"Prefs:root=WIFI". Note that the P in Prefs is capitalized.
    There are also disadvantages to writing this way. If Apple's undisclosed method is once modified, we must re- Make changes

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:50:49

    You haven’t set the url scheme of your application

    reply
    0
  • PHPz

    PHPz2017-04-18 09:50:49

    Writing like this in ios10, a great guy in the group taught me
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:50:49

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

    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);

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:50:49

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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:50:49

        NSURL *url = [NSURL URLWithString:@"prefs:root=com.testproject.testname"];
            [[UIApplication sharedApplication]openURL:url
    
    ];
    这样就OK吧  里面写你的项目名字 可以跳去

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:50:49

    I encountered the same problem, have you solved it?

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:50:49

    Have you solved it?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:50:49

    Please ask the poster how to solve it?

    reply
    0
  • Cancelreply