Search code examples
xcodeios7ios8xcode6quickblox

Xcode 6 - Remote Notifications in iOS8


My application uses QuickBlox to allow users to chat and receive push notifications. It works great in iOS7 and lower, but in iOS8, I am getting an error that remoteNotifications are not allowed.

iOS8 users are not shown the pop-up to ask them to approve push notifications anymore either.

Here is my pList

<key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
    </array>

And here is the relavant code in my .m file

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 

Any advice?


Solution

  • Support only iOS8 Notifications:

    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];  
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];  
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    

    Support both iOS7 and iOS8 Notifications:

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }
    

    Replace your existing registerForRemoteNotificationTypes line with the above code.


    Source: Push Notifications in iOS 7 & 8