Push notification not receiving in iOS 10
Asked Answered
T

4

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

Theoretics answered 15/9, 2016 at 6:26 Comment(7)
try this type code: #39383352Override
I checked the previous solution. But my app don't have iOS 10 SDK. Then how it should affect for iOS 10.Theoretics
you are download or upgrade your xcode 8 may be upgrade xcode.Override
For me older app which is already in AppStore is not workingTheoretics
add new framework in xcode 8 for push notification. all push notification app on app store is not working in ios 10 that it is upgrade your application on xcode 8.Override
Possible duplicate of Handling user notifications on iOS 10Sparkie
Possible duplicate of Push Notification is not working on iOS 10Override
N
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

Nowak answered 15/9, 2016 at 10:53 Comment(3)
Faced same issue. So I have re-submitted my apps to Appstore with xCode 8 GM for iOS 10.Nowak
@AshishShah No need to implement UserNotification. It can still be done with UIUserNotificationSettings. You just need to enable the capabilities for Push notifications which will make a .entitlement file in your project.Bradybradycardia
I agree with @RaRevere
E
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>
Elsie answered 15/12, 2016 at 13:37 Comment(0)
W
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();
}
Wily answered 26/9, 2016 at 4:22 Comment(1)
Not necessary, we can still use the same UIUserNotification for iOS 10. Only difference is to add the Push Notifications entitlement in CapabilitiesBradybradycardia
T
1

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

Theocracy answered 18/10, 2016 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.