gpt4 book ai didi

ios - 使用 -ObjC/-all_load 链接器标志时找不到符号

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:42:16 24 4
gpt4 key购买 nike

更新到 Xcode6 后,我在 IOS 7 上遇到此代码崩溃并显示“找不到符号:_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];
}

最佳答案

我认为您正在使用“基础 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] registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
#endif

关于ios - 使用 -ObjC/-all_load 链接器标志时找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25989897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com