• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:09:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

更新到 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-推荐答案


我认为您正在使用 '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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap