Xcode 6.3中的“打开设置”警告问题:“UIApplicationOpenSettingsURLString”的地址与“空指针”的地址比较始终为true [英] Open Settings warning issue in Xcode 6.3: Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true
问题描述
我不是在发明轮子。在iOS8中,要从应用程序内部打开设置我正在使用此代码:
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];
}
代码在stackoverflow中有很多答案和问题。
The code is in a lot of answers and questions in stackoverflow.
问题出现在Xcode 6.3上,我有一个警告说:
The problem came out with Xcode 6.3, I've got a warning saying:
比较'UIApplicationOpenSettingsURLString'的地址不等于空指针总是为真
有趣的是Apple在他们的示例代码中使用它:
https://developer.apple.com/library/ ios / samplecode / AppPrefs / Listings / RootViewController_m.html
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?
推荐答案
已解决:
问题是相关的使用应用程序中的部署目标。
The problem is related with the Deployment Target in the App.
如果是Targ et是8.0或更高版本,比较将始终为真,因为您总是超过8.0。所以我们不需要if验证:
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];
另一种选择可以是:
NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
{
[[UIApplication sharedApplication] openURL:settings];
}
这篇关于Xcode 6.3中的“打开设置”警告问题:“UIApplicationOpenSettingsURLString”的地址与“空指针”的地址比较始终为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!