Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);

if (canOpenSettings)
{
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:url];
}

The code is in a lot of answers and questions in stackoverflow.

The problem came out with Xcode 6.3, I've got a warning saying:

Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true

What is interesting is that Apple is using it in their example code:
https://developer.apple.com/library/ios/samplecode/AppPrefs/Listings/RootViewController_m.html

Some idea about how to avoid the warning and still checking if I can open Settings?

like image 668
Gabriel.Massana Avatar asked Apr 10 '15 10:04

Gabriel.Massana


2 Answers

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];
}
like image 75
Gabriel.Massana Avatar answered Oct 04 '22 16:10

Gabriel.Massana


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];
like image 32
Schemetrical Avatar answered Oct 04 '22 17:10

Schemetrical