【发布时间】:2014-09-23 07:59:31
【问题描述】:
更新到 Xcode6 后,我在 IOS 7 上遇到此代码崩溃,显示为“Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings”,任何人都可以帮助解决它
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]){
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}
编辑: 大家好, 这是运行时崩溃,而不是编译时链接错误,
异常类型:EXC_BREAKPOINT (SIGTRAP) 异常代码:0x0000000000000001、0x00000000e7ffdefe 线程触发:0
Dyld 错误消息: 未找到符号:_OBJC_CLASS_$_UIUserNotificationSettings
我使用的是 Xcode 6.0 (6A313),所以我不应该使用任何 #if 来指示 iOS 版本。此代码在 IOS 8 模拟器上运行良好,但在 IOS 7 设备上崩溃
编辑 2:
最后,这个问题被这些代码解决了,我已经在下面标记了正确的答案,谢谢 trojanfoe。
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
Class userNotifyClass = NSClassFromString(@"UIUserNotificationSettings");
if(userNotifyClass != nil)
{
id notifyInstance = [userNotifyClass settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:notifyInstance];
[application registerForRemoteNotifications];
}
}
else
{
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}
【问题讨论】:
-
“代码崩溃”是指“链接错误”?
-
@Daij-Djan 对不起,我不明白你的意思。
-
你在 ARM64 上测试吗?
-
提供屏幕截图、您测试的硬件等。
-
嗨,Andy,我使用 iTouch 5 和 7.1.1,有效架构 armv7,基础 sdk IOS 8.0。
标签: ios objective-c linker