Open Settings warning issue in Xcode 6.3: Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true

后端 未结 2 965
南旧
南旧 2021-01-12 10:19

I\'m not inventing the wheel. In iOS8, to open Settings from inside the app I\'m using this code:

BOOL canOpenSettings = (&UIApplicationOpenSettingsURLSt         


        
相关标签:
2条回答
  • 2021-01-12 11:03

    I believe this is because &UIApplicationOpenSettingsURLString is never nil in this version so you can just directly use the following to launch settings:

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:url];
    
    0 讨论(0)
  • 2021-01-12 11:10

    SOLVED:

    The problem is related with the Deployment Target in the App.

    screenshot

    If the Target is 8.0 or above, the comparison will be always true because you are always over 8.0. So we do not need the if verification:

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:url];
    

    Another option can be:

    NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:settings])
    {
        [[UIApplication sharedApplication] openURL:settings];
    }
    
    0 讨论(0)
提交回复
热议问题