相关疑难解决方法(0)

registerForRemoteNotificationTypes:iOS 8.0及更高版本不支持

尝试在iOS 8.x下注册推送通知时:

application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
Run Code Online (Sandbox Code Playgroud)

任何想法是什么新的做法?当我在iOS 7.x上运行这个Swift应用程序时,它确实有效.

编辑

在iOS 7.x上,当我包含我得到的条件代码时(SystemVersion条件或#if __IPHONE_OS_VERSION_MAX_ALLOWED> = 80000)

dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
Run Code Online (Sandbox Code Playgroud)

objective-c dyld apple-push-notifications ios8

209
推荐指数
6
解决办法
10万
查看次数

什么是Swift预处理器相当于iOS版本检查比较?

我正进入(状态

yld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
Run Code Online (Sandbox Code Playgroud)

这是当应用程序在iOS7设备上运行时甚至根本没有在代码中调用该函数导致错误的函数.

func reigsterForRemoteUserNotifications(notificationTypes: UIUserNotificationType, categories: NSSet) {
        let userNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categories)
        (UIApplication.sharedApplication()).registerUserNotificationSettings(userNotificationSettings)
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
Run Code Online (Sandbox Code Playgroud)

我不希望在iOS7设备上运行时可以访问此方法.我不希望在其中进行选择检查,因为这意味着该方法可用于开始.

我想要的是一个构建配置参数来检查版本:我无法找到一种方法来编写一个快速等效的预处理器宏来检查正确的iOS版本并忽略新的和未声明的iOS 8库函数.

#if giOS8OrGreater
// declare the functions that are iOS 8 specific
#else 
// declare the functions that are iOS 7 specific

#endif
Run Code Online (Sandbox Code Playgroud)

在文档中,apple建议使用函数和泛型来替换复杂的宏,但在这种情况下,我需要构建配置预编译检查以避免处理未声明的函数.有什么建议.

macros ios swift

18
推荐指数
3
解决办法
1万
查看次数

标签 统计

apple-push-notifications ×1

dyld ×1

ios ×1

ios8 ×1

macros ×1

objective-c ×1

swift ×1