Yogesh MV
Yogesh MV

Reputation: 1051

Push notification not receiving in iOS 10

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

Upvotes: 9

Views: 21628

Answers (4)

Ashish Shah
Ashish Shah

Reputation: 2350

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

Upvotes: 7

arango_86
arango_86

Reputation: 4435

"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>

Upvotes: 7

raul
raul

Reputation: 101

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

Upvotes: 1

Keyur Hirani
Keyur Hirani

Reputation: 1607

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();
}

Upvotes: 3

Related Questions