didRegisterForRemoteNotificationsWithDeviceToken 未在 ios8 中调用,但 didRegister...Settings 是 [英] didRegisterForRemoteNotificationsWithDeviceToken not called in ios8, but didRegister...Settings is
问题描述
我关注了这个线程,但是方法didRegisterForRemoteNotificationsWithDeviceToken
仍然没有被调用:
I followed this thread, but the method didRegisterForRemoteNotificationsWithDeviceToken
is still not called :
文档说:
调用 registerForRemoteNotifications 方法后UIApplication 对象,应用程序在设备时调用此方法注册成功
After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully
didRegisterUser
看起来不错,但不是 did register notif
.
didRegisterUser
appears well, but not did register notif
.
这是我在 AppDelegate 中的代码(应用程序版本为 8.1):
Here is my code in the AppDelegate (the app version is 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 中的远程通知.
I also have background mode -> remote notification in the info.plist.
推荐答案
您的代码似乎是正确的.作为一个小的改进,你可以像这样编写你的 didRegisterUserNotificationSettings 方法:
Your code seems to be correct. As a minor improvement you could write your didRegisterUserNotificationSettings method like so:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
if (notificationSettings.types != UIUserNotificationTypeNone) {
NSLog(@"didRegisterUser");
[application registerForRemoteNotifications];
}
}
可能是配置问题导致APN注册失败.
There may be a configuration problem that causes a failed APN registration.
确保您的配置文件包含 aps-environment 条目
Assure that your Provisioning Profile contains the aps-environment entry
确保您的配置文件中设置了唯一的应用程序标识符(不带任何*"的字符串).您还应该在 Info.plist 中将此确切标识符用作捆绑标识符"
Assure that you have a unique App Identifier (a string without any "*") set in your Provisioning Profile. You should also use this exact identifier as "Bundle identifier" in your Info.plist
也许您在初始安装后拒绝了推送功能 - 在这种情况下,您将永远不会再看到 in-app-push-alert 并且必须再次在设置应用程序中启用推送.
Maybe you have declined the Push-Feature after the initial installation - in this case you will never see the in-app-push-alert again and have to enable Push in the settings app again.
尝试其他设备.
这篇关于didRegisterForRemoteNotificationsWithDeviceToken 未在 ios8 中调用,但 didRegister...Settings 是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!