registerForRemoteNotificationTypes:不支持的iOS 8.0及更高版本 [英] registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

查看:170
本文介绍了registerForRemoteNotificationTypes:不支持的iOS 8.0及更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图根据iOS版8.x的推送通知注册:

  application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)

我收到以下错误:

  registerForRemoteNotificationTypes:在IOS 8.0及更高版本不支持。

任何想法是做它的新途径?当我运行在iOS 7.x的这个斯威夫特应用它的工作。

修改

在iOS 7.x的时候我加入了条件code我得到的(无论是SystemVersion有条件或#如果__IPHONE_OS_VERSION_MAX_ALLOWED> = 80000)

未找到符号:

  dyld的_OBJC_CLASS _ $ _ UIUserNotificationSettings


解决方案

如您所述,您将需要使用基于不同版本的iOS不同的方法。如果你的团队同时使用X code 5(不知道任何iOS 8的选择)和X code 6(目前处于测试阶段),那么你就需要使用条件编译如下:

 #如果__IPHONE_OS_VERSION_MAX_ALLOWED> = 80000
如果([应用respondsToSelector:@selector(registerUserNotificationSettings :)]){
    //使用registerUserNotificationSettings
}其他{
    //使用registerForRemoteNotificationTypes:
}
#其他
//使用registerForRemoteNotificationTypes:
#万一

如果您只使用X code 6(测试版),你可以坚持眼前这个:

 如果([应用respondsToSelector:@selector(registerUserNotificationSettings :)]){
    //使用registerUserNotificationSettings
}其他{
    //使用registerForRemoteNotificationTypes:
}

原因是这里是你获得通知权限的方式的iOS 8.改变了 UserNotification 是远程或本地显示给用户,无论是消息。你需要得到许可显示一个。这是在2014年WWDC视频是什么在iOS中通知的新

When trying to register for push notifications under iOS 8.x:

application.registerForRemoteNotificationTypes(UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)

I get the following error:

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

Any ideas what is the new way of doing it? It does work when I run this Swift app on iOS 7.x.

EDIT

On iOS 7.x when I include the conditional code I get (either SystemVersion conditional or #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000)

dyld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings

解决方案

As you described, you will need to use a different method based on different versions of iOS. If your team is using both Xcode 5 (which doesn't know about any iOS 8 selectors) and Xcode 6 (currently in beta), then you will need to use conditional compiling as follows:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    // use registerUserNotificationSettings
} else {
    // use registerForRemoteNotificationTypes:
}
#else
// use registerForRemoteNotificationTypes:
#endif

If you are only using Xcode 6 (beta), you can stick with just this:

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    // use registerUserNotificationSettings
} else {
    // use registerForRemoteNotificationTypes:
}

The reason is here is that the way you get notification permissions has changed in iOS 8. A UserNotification is a message shown to the user, whether from remote or from local. You need to get permission to show one. This is described in the WWDC 2014 video "What's New in iOS Notifications"

这篇关于registerForRemoteNotificationTypes:不支持的iOS 8.0及更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆