Push notification not receiving in iOS 10

点点圈 提交于 2019-12-18 12:29:17

问题


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


回答1:


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




回答2:


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



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



回答4:


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



来源:https://stackoverflow.com/questions/39504334/push-notification-not-receiving-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!