注意:这显然是由于设置中的某种损坏,代码显然一直很好......
在此主题中的对话之后:Remote Notification iOS 8,我将此样板代码添加到我的应用中:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeBadge categories:nil]];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
}
if ([[inLaunchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {
[appTracking registerPush:[inLaunchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}
我还添加了application:didRegisterUserNotificationSettings
处理程序,它调用一行代码[application registerForRemoteNotifications]
。应用启动时会调用此代码 。
读取该线程,建议这就是所需要的,这将导致application:didRegisterForRemoteNotificationsWithDeviceToken
被调用。但这绝对是不在我的应用中发生。
我是否错过了一个步骤,或者只是误解了如何设置它?
答案 0 :(得分:0)
您需要在[application registerForRemoteNotifications]
iOS 8条件
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
祝你好运
答案 1 :(得分:0)
试试这个:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}