Xcode 6.3中的Open Settings警告问题:'UIApplicationOpenSettingsURLString'的地址比较不等于空指针始终为true

Gab*_*ana 7 objective-c uiapplication ios xcode6.3

我不是在发明轮子.在iOS8中,要从应用程序内部打开"设置",我正在使用此代码:

BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);

if (canOpenSettings)
{
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:url];
}
Run Code Online (Sandbox Code Playgroud)

代码在stackoverflow中有很多答案和问题.

问题出现在Xcode 6.3上,我有一个警告说:

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

有趣的是Apple在他们的示例代码中使用它:https:
//developer.apple.com/library/ios/samplecode/AppPrefs/Listings/RootViewController_m.html

关于如何避免警告并仍然检查我是否可以打开设置的一些想法?

Gab*_*ana 14

解决了:

该问题与应用程序中的部署目标有关.

截图

如果目标是8.0或更高,则比较将始终为真,因为您总是超过8.0.所以我们不需要if验证:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
Run Code Online (Sandbox Code Playgroud)

另一种选择可以是:

NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
{
    [[UIApplication sharedApplication] openURL:settings];
}
Run Code Online (Sandbox Code Playgroud)