0

I use APNS and it's work fine on iOS 9. With the new push API changes on iOS10 i cant register for push notification so i insert the next changes:

  1. Enable push notification in the target capabilities tab.
  2. In didFinishLaunchingWithOptions we check the OS version and register as followed :

    if (SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")) {
    
        //ios 10 Notifiction
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
            if( !error ){
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                NSLog(@"iOS 10 push notification register successfully ");
            }
        }];
    } else {
        // iOS 8-9 Notifications
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        NSLog(@"iOS 9 push notification register successfully ");
    
    }
    

With this changes I manage to perform registration in iOS 9 and iOS 10 but I have couple of problems :

  1. Once I enable the push notification in the target capabilities tab the push notification stop working on iOS 9 although the registration was complete successfully .
  2. The push doesn’t work on iOS 10 at all although the registration was complete successfully .

Please keep in mind that if I turn off the push notification in the target capabilities tab (with the same code) the push return to work on iOS 9 but I cant register for APNS on iOS 10.

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
  • see this once http://stackoverflow.com/questions/39267549/ios-how-to-integrate-push-notification-in-ios-10/39268135#39268135 – Anbu.Karthik Dec 05 '16 at 09:32
  • already try this too. enabled Push Notification in capabilities tab, added UserNotifications framework and UNUserNotificationCenterDelegate, check the OS version and register completed successfully in both OS version. the problem is that didReceiveRemoteNotification doesn't call. i don't need to know about the user action in the notification but i implemented the didReceiveRemoteNotification:userInfo fetchCompletionHandler as well – Oded Dilmoni Dec 05 '16 at 13:16

1 Answers1

0
    if #available(iOS 8.0, *) {
        let settings: UIUserNotificationSettings = UIUserNotificationSettings (types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    }else {
        let types: UIRemoteNotificationType = [.alert, .badge, .sound]
        application.registerForRemoteNotifications(matching: types)
    }
rony_y
  • 535
  • 1
  • 8
  • 26