我关注了this thread ,但是方法 didRegisterForRemoteNotificationsWithDeviceToken
仍然没有被调用:
文档说:
After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully
didRegisterUser
看起来不错,但不是did register notif
。
这是我在 AppDelegate 中的代码(应用程序版本是 8.1):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register notif
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"didRegisterUser");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error here : %@", error);//not called
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/*
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
*/
NSLog(@"did register notif");//not called
}
我在 info.plist 中也有后台模式 -> 远程通知。
最佳答案
经过长时间的挖掘,我发现在 2016 年 7 月 19 日,由于 Apple 端的一些错误或更新,即使互联网连接、设备和用的方法很完美。
请引用此链接进行确认https://forums.developer.apple.com/thread/52224
要验证,请同时查看您的其他应用。 我浪费了几个小时,但希望它能帮助别人。 谢谢。
关于ios - didRegisterForRemoteNotificationsWithDeviceToken 没有在 ios8 中调用,但是 didRegister...Settings 是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28128490/