9

My App is in Appstore. Push notification is working fine in iOS 9, but in iOS 10 it is not working. I am not receiving any push notification for iOS 10 devices. I have checked the device token and certificate in my server. All are correct. I have also checked the notification properties in settings app. All are fine. But I didn't receive any notification. I just switch OFF and ON the notification for my app. And I opened my app to check whether device token is changing or not. It is changed and updated to my server. Then I am receiving notification properly. It is working fine now for my device.

I am worried whether this will affect for all users or only me. Anyone find the proper solution please let me know.

Thanks in advance

Yogesh Mv
  • 1,041
  • 1
  • 6
  • 12

4 Answers4

7

Need some changes for iOS 10 with xCode 8 GM You need to implement UserNotifications.framework and their delegate methods to get work of push notifications.

I have resolved my issue using new UserNotifications.framework. Please follow this link : Push notification issue with iOS 10

Abdul Saleem
  • 10,098
  • 5
  • 45
  • 45
Ashish Shah
  • 2,361
  • 1
  • 20
  • 20
7

"UserNotifications" is not mandatory in iOS10. "UIUserNotificationSettings" still works in iOS10.

If you have the following code , it should work in iOS10.

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

But if you are building with Xcode8 and above, makes sure that you have the following entry in your entitlements. This entry will be added automatically once you enabled "Push Notifications" in "Capabilities".

<key>aps-environment</key>
<string>development</string>

In release-distribution build this will be automatically changed to the following

<key>aps-environment</key>
<string>production</string>
arango_86
  • 4,236
  • 4
  • 40
  • 46
3

We need to change some code for iOS 10.

Appdelegate.h

#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> 
@end

Check os version

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

Register notification

- (void)registerForRemoteNotifications {
    if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
             if(!error){
                 [[UIApplication sharedApplication] registerForRemoteNotifications];
             }
         }];  
    }
    else {
        // Code for old versions
    }
}

Handel delegate method

//foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
    NSLog(@"User Info : %@",notification.request.content.userInfo);
    completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
    NSLog(@"User Info : %@",response.notification.request.content.userInfo);
    completionHandler();
}
Keyur Hirani
  • 1,607
  • 14
  • 22
  • 1
    Not necessary, we can still use the same `UIUserNotification` for iOS 10. Only difference is to add the Push Notifications entitlement in Capabilities – Rajan Maheshwari Nov 24 '16 at 06:20
1

On iOS 10 is necessary add the Push Notifications entitlement, so if you "Fix Issue" in Capabilities the problem will be resolved automatically.

raul
  • 101
  • 2
  • 7