13

I have upgraded my devices to iOS 9 and my Xcode environment to 7.0 beta. Push notifications are not working in iOS 9?

Here is my code:

  float ver = [[[UIDevice currentDevice] systemVersion] floatValue];

    if(ver >= 8 && ver<9)
    {
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
            [[UIApplication sharedApplication] registerForRemoteNotifications];
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        }
    }else if (ver >=9){

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];


    }
    else{
        //iOS6 and iOS7 specific code
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
    }

Push notifications are working fine on iOS 8 to 8.3 built with Xcode 6.4.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Anil Kukadeja
  • 1,348
  • 1
  • 14
  • 27
  • I'm running into the same problem. Let me know if you find a solution – user2981810 Sep 23 '15 at 04:31
  • Does anyone find a solution for this? I'm running into the same issue. – James Laurenstin Sep 28 '15 at 20:30
  • I am also getting the same problem.. – Hari Babu Oct 06 '15 at 17:04
  • I'm having the same problem, push notifications were working for me, even on iOS 9 and xcode 7, last week I upgraded to El Capitan and XCode 7.1 and iOS 9.1 and then they stopped working, I've only tested my development environment but will test others. Need a solution for this asap if anyone has any ideas please help. I've tried regenerating the certificates using Ray's tutorial which has always worked, except for this time – crojassoto Nov 03 '15 at 16:27
  • [Registering Notifications for iOS 9 using Swift 2](http://stackoverflow.com/a/33009043/3288182) – Scar Nov 23 '15 at 06:10
  • @Scar : I guess it does the same stuff with all conditions written above. – Anil Kukadeja Nov 23 '15 at 13:30
  • Does it helpful check it out: http://www.intertech.com/Blog/push-notifications-tutorial-for-ios-9/ – SamSol Nov 24 '15 at 05:42

5 Answers5

5

After adding the code in your project and creating the certificate and Ad-Hoc Profile -

*Just enable this from your X-code*

enter image description here

for more details - iOS 9 Push Notification Tutoriyal

Abhishek Mishra
  • 1,625
  • 16
  • 32
  • This happened to me after the upgrade of the project from swift 2 to 3. Whats annoying is that -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken is still called regardless - You just won't receive the notification unless this option is checked. – Chris Birch Sep 20 '16 at 12:26
  • Did the trick for me. I also upgraded the project from Swift 2.0 to 3.0 when moving to XCode 8. – oztune Oct 18 '16 at 19:17
  • Yes, it is same for Swift 3.0 and X-Code 8 too. – Abhishek Mishra Nov 09 '16 at 09:31
-1

I ran into the same problem. I solved it by creating an Ad-Hoc Profile. I noticed push is not happening when I use a development profile. And the other thing I noticed was the Device Token gets changed for every fresh install which is kind of weird as we have to update the server for every new instance.

You can go through this article for a better understanding : iOS 9 Push Notifications

Sreejith
  • 1,345
  • 13
  • 25
  • I do know that device token keeps changing on fresh install. That's not the probelm. I do send device_token on login everytime. – Anil Kukadeja Oct 26 '15 at 05:32
  • Did you try using adhoc profile? For me both the dev and distribution certs seems to be working. – Sreejith Oct 27 '15 at 01:37
  • 1
    Yes. I have tried. As I have mentioned above you know notifications are working on iOS 8 using same profile but not for iOS 9. – Anil Kukadeja Oct 27 '15 at 05:27
-2

write this code in didFinishLaunchingWithOptions

 UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

and add this method to AppDelegate as i have used for parse push notification service

 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
}
sp309
  • 150
  • 1
  • 10
-2

Please try this code as its working for my IOS 9 application

Write a Code in AppDelegate DidFinishLaunchWithOption

if([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:  [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
   #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)]; #endif
}

Make sure the following items are well checked for the Push notification on the server

  1. PEM File generated with selecting the Cert & Private key from the originator
  2. Apple service enabled and pointing to Sandbox/Live correctly
  3. Push notification token is received in below function and not any Error is returned which is well send to the server (LAMP service) that is sending the APNS Push notification to device Token.
  4. Check the Apple APNS response code in the server with the Push send to the token.
  5. Enabled Push notification in the settings as if you do any goof up in the '|' symbol code you may see the sound, badge options not shown in Apple General Notification settings

    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
        {
            NSString *devicetokenString = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    
            DLog(@"Did Register for Remote Notifications with Device Token DATA (%@) \n STRING token (%@)", deviceToken,devicetokenString);
    
            //If Same token received again dont take any action else save in NSUserdefaults or system and send to server to register against this device to send push notification on the token specified here.
        }
    
    -(void)application:(UIApplication *)application    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 
        {
            DLog(@"Did Fail to Register for Remote Notifications");
            DLog(@"%s:%@, %@",__PRETTY_FUNCTION__,error, error.localizedDescription);
        }
    
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        {
            DLog(@"Did Receive for Remote Notifications with UserInfo:%@", userInfo);
        }
    

Hope this is well explained if any help do post your updated code so we can help you.

codelover
  • 1,113
  • 10
  • 28
-2

If you are using Diawi for install application than push notification not working in IOS 9..

You install application though Xcode..

Chandra Kumar
  • 4,127
  • 1
  • 17
  • 25