Phillip
Phillip

Reputation: 4306

Push notification alert not working on iOS 7 but it does on iOS 8

I want to implement push notifications in my app.

In iOS 8, at the app launch, the user gets the classic "Would you like app to send notifications?", but in iOS 7 it doesn't work and I fail to understand why.

This is the code I'm using

if ([application 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)];
}

In iOS 8 it works pretty much, but iOS 7 doesn't.

Any clue why is this not working?

I made and use all the necessary certificates.

Upvotes: 0

Views: 417

Answers (1)

Hussain Shabbir
Hussain Shabbir

Reputation: 14995

Your code looks good only but try using the below trick:-

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0  
    if ([application 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)];  
    }  
#else  
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];  
#endif  

Upvotes: 2

Related Questions