Push Notification Issue With iOS 10

Push notification not receiving in iOS 10

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

Push notification issue with iOS 10

For iOS 10 using xCode 8 GM.

I have resolved my issue with following steps using xCode 8 GM for iOS 10:

1) In the targets, under Capabilities enable Push Notifications to add Push Notifications Entitlements.

2) Implement UserNotifications.framework into your app. Import UserNotifications.framework in your AppDelegate.

#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>

@end

3) In didFinishLaunchingWithOptions method assign UIUserNotificationSettings and implement UNUserNotificationCenter delegate.

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

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

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];
}
}];
}

return YES;
}

4) Now finally implement this two delegate methods.

//============For iOS 10=============

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{

//Called when a notification is delivered to a foreground app.

NSLog(@"Userinfo %@",notification.request.content.userInfo);

completionHandler(UNNotificationPresentationOptionAlert);
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{

//Called to let your app know which action was selected by the user for a given notification.

NSLog(@"Userinfo %@",response.notification.request.content.userInfo);

}

Please remain the code as it is you are using for iOS 9,
Only add lines of code to support Push notification for iOS 10 using UserNotifications.framework.

Push Notification is not working on iOS 10

Need some changes for iOS 10 with xCode 8 GM You need to implement UserNotification.framework and their delegate methods to get work of push notifications and in capabilities needs to enable Push Notifications.

You have to import new UserNotification.framework. Please follow this link : Push notification issue with iOS 10

Sound issues fixes for iOS 10 Push Notifications

Has Apple completely fixed this issue in any version? If so what
version?

Based on JAL's comment Apple has fixed in iOS 10.2.

After a hard reboot, would the problem completely go away? Or you need
to do it again? if so when?

Based on leontx's comment, For those users who are using iOS 10.0.x or 10.1.x they would only need to do a single hard reset.

Push Notifications not being received on iOS 10, but working on iOS 9 and before

Ok I have figured it out. I now have my original Push Notifications that was working on iOS 9 working on iOS 10 with Xcode 8 and Swift 2.3.

I implemented this by making the following changes to my AppDelegate:

1) On my project settings, under the Capabilities Tab, I scroll down to "Push Notifications" and turn it to "ON". This automatically generates an entitlements file that contains the key "APS Environment" and with value "development".

2) In AppDelegate.swift I make several code changes. I start by importing the UserNotifications framework:

import UserNotifications

Then I have AppDelegate implement the UNUserNotificationCenterDelegate protocol:

class AppDelegate: /*Some other protocols I am extending...*/, UNUserNotificationCenterDelegate {

Then I add the following method:

func registerForPushNotifications(application: UIApplication) {

if #available(iOS 10.0, *){
UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert], completionHandler: {(granted, error) in
if (granted)
{
UIApplication.sharedApplication().registerForRemoteNotifications()
}
else{
//Do stuff if unsuccessful...
}
})
}

else{ //If user is not on iOS 10 use the old methods we've been using
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)

}

}

Then I call this newly created function inside didFinishLaunchingWithOptions:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
...
registerForPushNotifications(application)
...
}

I leave my didRegisterForRemoteNotificationsWithDeviceToken method unchanged:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
//Implement this. Do something with the token I receive. Send it to my push notification server to register the device or something else I'd like to do with the token.
}

Now I implement two new methods for iOS 10 to handle the receiving of Push Notifications:

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
//Handle the notification
}

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
//Handle the notification
}

I did not remove any of the methods I have previously implemented for Push Notifications in iOS 9.

Apple Push Notifications not received in iOS 9/10 after switching it on Capabilities

I found solution, in my case: Before iOS 10 we used only Production sertificate to test push, it work fine, but after iOS 10 pushes do not receive in app runing with Xсode(but receive in TestFlight), after we create and use developer certificate to sign pushes - it work again

Trouble receiving push notifications in iOS10 and iOS9

Going to answer this, maybe it will be useful for other. My token was wrong. The encoding has changed with recent updates. I did actually search all over stack overflow for this and it was to my understanding that I had to convert the Data to a String using the base64string. However I noticed this string had a few odd characters in it such as \. I eventually ended up making a Data extension:

extension Data {

func hexString() -> String {
return self.reduce("") { string, byte in
string + String(format: "%02X", byte)
}
}

}

This converts the Data to the correct format. So if this is how you do your conversion, plus all the entitlements are set, you remember to add the new methods:

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("Got a push!")
}


@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("Got a push!")
}

and set the delegate object in didFinishLaunchingWithOptions everything should be good to go.



Related Topics



Leave a reply



Submit