IOS 11 didRegisterForRemoteNotificationsWithDeviceToken未调用

时间:2017-10-02 22:13:53

标签: ios objective-c iphone push-notification ios11

调用registerForRemoteNotifications后,不会调用appDelegate方法didRegisterForRemoteNotificationsWithDeviceToken。我没有从APN收到令牌,因此我无法收到推送通知。

我看到弹出'允许',但在选择允许后,我没有得到didRegisterForRemoteNotificationsWithDeviceToken的常规响应。

IOS 11之前的所有工作都已经过去了。

还有其他人遇到同样的问题吗?对我的问题似乎没有太多抱怨。

在APN注册过程中,IOS 11有什么变化吗? 当应用程序在后台运行时,IOS 10中的didReceiveRemoteNotification也无效。

我已经搜索了高低的修复程序,但是对于IOS 11来说,推送通知对我来说只是打破了。

我正确设置了所有Info.plist数据。 我在项目设置中设置了所有开关。 我测试过我们的应用程序的早期版本。 我已经创建了一个简单的骨骼项目,它也不起作用,就像我们的生产应用程序一样。 我假设注册码与IOS 10相同。

请SOS! 感谢。

2 个答案:

答案 0 :(得分:0)

AppDelegate类方法didFinishLaunchingWithOptions中,您必须使用代码 -

if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) )
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound |    UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];

        if( optind != nil )
        {
            NSLog( @"registerForPushWithOptions:" );
        }
    }
    else
    {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
         {
             if( !error )
             {
                 [[UIApplication sharedApplication] registerForRemoteNotifications];  // required to get the app to do anything at all about push notifications
                 NSLog( @"Push registration success." );
             }
             else
             {
                 NSLog( @"Push registration FAILED" );
                 NSLog( @"ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription );
                 NSLog( @"SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
             }
         }];
    }

并添加以下framework -

enter image description here

答案 1 :(得分:0)

我也试过这个解决方案但没有成功。

我们的团队实际上解决了这个问题。一名团队成员注意到didRegisterForRemoteNotificationsWithDeviceToken正在使用Xcode 9和IOS 11。

只需将我的iPhone 6s plus设备插入电脑并运行应用程序,问题就消失了。

设备现在收到didRegisterForRemoteNotificationsWithDeviceToken。

我正在将这个问题归咎于某些IOS更新的怪异。

感谢您的帮助。