ios - 使用 -ObjC/-all_load 链接器标志时找不到符号
<p><p>更新到 Xcode6 后,我在 IOS 7 上遇到此代码崩溃,出现“<code>Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings</code>”,谁能帮忙解决一下</p>
<pre><code>if (){
UIUserNotificationSettings *settings = ;
[ registerUserNotificationSettings:settings];
[ registerForRemoteNotifications];
}
else {
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[ registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}
</code></pre>
<p>编辑:
大家好,
这是运行时崩溃,而不是编译时链接错误,</p>
<p>异常类型:EXC_BREAKPOINT (SIGTRAP)
异常代码:0x0000000000000001、0x00000000e7ffdefe
线程触发:0</p>
<p>Dyld 错误消息:
未找到符号:_OBJC_CLASS_$_UIUserNotificationSettings</p>
<p>我使用的是 Xcode 6.0 (6A313),所以我不应该使用任何 #if 来指示 iOS 版本。此代码在 IOS 8 模拟器上运行良好,但在 IOS 7 设备上崩溃</p>
<p>编辑 2:</p>
<p>最后,这些代码解决了这个问题,我已经在下面标记了正确的答案,谢谢 trojanfoe。</p>
<pre><code> if ()
{
Class userNotifyClass = NSClassFromString(@"UIUserNotificationSettings");
if(userNotifyClass != nil)
{
id notifyInstance = ;
;
;
}
}
else
{
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[ registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您正在使用 'base SDK' 7.x 构建您的项目
因此,您可以将其更改为 <strong>8.0</strong> 或在编译期间检查当前版本:</p>
<pre><code>#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
UIUserNotificationSettings *settings = ;
[ registerUserNotificationSettings:settings];
[ registerForRemoteNotifications];
#else
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[ registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
#endif
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用 -ObjC/-all_load 链接器标志时找不到符号,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25989897/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25989897/
</a>
</p>
页:
[1]