更新到 Xcode6 后,我在 IOS 7 上遇到此代码崩溃,出现“Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings ”,谁能帮忙解决一下
if ([application respondsToSelectorselector(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] registerForRemoteNotificationTypesUIRemoteNotificationType)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 respondsToSelectorselector(registerUserNotificationSettings])
{
Class userNotifyClass = NSClassFromString(@"UIUserNotificationSettings");
if(userNotifyClass != nil)
{
id notifyInstance = [userNotifyClass settingsForTypesUIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:notifyInstance];
[application registerForRemoteNotifications];
}
}
else
{
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypesUIRemoteNotificationType)notifyType];
}
Best Answer-推荐答案 strong>
我认为您正在使用 'base SDK' 7.x 构建您的项目
因此,您可以将其更改为 8.0 或在编译期间检查当前版本:
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
#else
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypesUIRemoteNotificationType)notifyType];
#endif
关于ios - 使用 -ObjC/-all_load 链接器标志时找不到符号,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/25989897/
|