ios - didRegisterForRemoteNotificationsWithDeviceToken 没有在 ios8 中调用,但是 didRegister...Settings 是

标签 ios objective-c apple-push-notifications ios13

我关注了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/

相关文章:

iphone - 如何检查设备是 LTE、3G、HSPA 还是 Wi-Fi?

ios - 在动态 TableView 中添加静态单元格

objective-c - XPC 和异常处理

ios - 如果应用程序已经运行,如何处理推送通知?

ios - 删除应用程序后获取推送通知的设备 token

javascript - 仅在 IOS 设备上加载 "window.open"命令......?

ios - 使用 Swift 和 Xcode 6 对 UIGestureRecognizer 进行子类化 - 如何导入 UIGestureRecognizerSubclass.h?

objective-c - Objective C - 后台执行选择器并且分离新线程选择器?

python - 如何从python服务器发送iOS推送通知?

ios - UIScrollView显示错误位置