RegisterUserNotificationSettings 在 ios 6.1 中不起作用 [英] RegisterUserNotificationSettings is not working in ios 6.1
问题描述
我在我的项目中使用 Parse SDK 进行推送通知.我在 didFinishLaunchingWithOptions:
中添加了代码,如 parse.com
I am using the Parse SDK for push notification in my project. I have added the code in didFinishLaunchingWithOptions:
as given on the parse.com
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
它工作正常,如果设备或模拟器版本是 iOS 8,但它不能在 iOS 6.1 中工作,并出现消息
its working fine, if device or simulator version is iOS 8, but its not working in iOS 6.1 ,and message appear
[UIApplication registerUserNotificationSettings:]: 无法识别的选择器发送到实例 0x208406c0
谁能告诉我怎么解决?
推荐答案
在 didFinishLaunchingWithOptions 方法中使用此代码它在 ios 6 和 7 中有效
use this code in didFinishLaunchingWithOptions method it is work in ios 6 and 7
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
如果您想在所有情况下都在 ios 6,7,8 中工作,请在 didFinishLaunchingWithOptions 中使用此代码
if you want to work in ios 6,7,8 in all cases then used this code inside a didFinishLaunchingWithOptions
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
这篇关于RegisterUserNotificationSettings 在 ios 6.1 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!