Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegisterUserNotificationSettings is not working in ios 6.1

I am using the Parse SDK for push notification in my project. I have added the code in didFinishLaunchingWithOptions: as given on the parse.com

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


[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];

its working fine, if device or simulator version is iOS 8, but its not working in iOS 6.1 ,and message appear

[UIApplication registerUserNotificationSettings:]: unrecognized selector sent to instance 0x208406c0

Can any one tell me how can i solve it?

like image 806
Ravi Ojha Avatar asked Dec 04 '14 12:12

Ravi Ojha


2 Answers

use this code in didFinishLaunchingWithOptions method it is work in ios 6 and 7

[application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

if you want to work in ios 6,7,8 in all cases then used this code inside a didFinishLaunchingWithOptions

 if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }
like image 147
SGDev Avatar answered Nov 15 '22 20:11

SGDev


For iOS8:

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)];
}
like image 32
Javier Calatrava Llavería Avatar answered Nov 15 '22 20:11

Javier Calatrava Llavería