在ios10上没有调用didRegisterForRemoteNotificationsWithDeviceToken

Tun*_*Fam 5 objective-c push-notification devicetoken ios10

我有2部iphone:1 - ios 10和2 - ios 9

在尝试第一款iphone时:

didRegisterForRemoteNotificationsWithDeviceToken当用户在警报上单击"允许"时,不调用方法但是,方法didRegisterUserNotificationSettingsIS被调用.在这种情况下,设备不会收到推送通知.

在尝试第二款iphone时:

这两种方法都在这里调用.设备可以接收推送通知.

然后我检查了模拟器ios 8

在这种情况下与第1次相同.只调用一种方法.

我检查了类似问题的一些答案,但他们没有帮助我.我怀疑这个问题是在推送通知设置中的某个地方,因为它可以正常工作.所以问题出在ios 10中.

问题是:

  1. 我怎么称呼方法 didRegisterForRemoteNotificationsWithDeviceToken
  2. 或者我如何获得设备令牌,因为它是目标

期待您的帮助!

Dar*_*eja 9

适用于使用xCode 8 GM的iOS 10.

通过以下步骤解决了此问题.要求: - Xcode 8 GM Seed.MAC OS: - EL 10.11.6上尉

请勿删除IOS 9或更低版本的代码.

步骤1: - 转到 - > Xcode中的目标设置 - >功能 - >启用PushNotifications.

第2步: - 添加UserNotifications框架 - >构建阶段 - >链接库

第3步: -

#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder   <UIApplicationDelegate,UNUserNotificationCenterDelegate>

@end
Run Code Online (Sandbox Code Playgroud)

步骤4: - 在方法didFinishLaunchingWithOptions中注册UIUserNotificationSettings.

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

    if(SYSTEM_VERSION_EQUALTO(@"10.0")){
        UNUserNotificationCenter *notifiCenter = [UNUserNotificationCenter currentNotificationCenter];
        notifiCenter.delegate = self;
        [notifiCenter requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
             if( !error ){
                 [[UIApplication sharedApplication] registerForRemoteNotifications];
             }
         }];  
    }

    return YES;
    }
Run Code Online (Sandbox Code Playgroud)

步骤5: -实现UNUserNotificationCenterDelegate的2个委托方法.

    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{

//Do Your Code.................Enjoy!!!!
    }

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{

}
Run Code Online (Sandbox Code Playgroud)