2

I want to use remote notification with deployment target 8.1 and xcode 6.1
i am using following code

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

But it shows me deprecated methods in else part....so now how can i get rid of it... and the other code what i tried is:

enter image description here

1
  • Are you sure that you have also as deployment target ios7 or lower? than make a clean build and build again
    – Andrea
    Mar 11, 2015 at 8:40

4 Answers 4

2

You could ignore deprecate warning like this:

#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 {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#pragma clang diagnostic pop

    }
#else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif

See this post:

0

Hope the following code might serve your need

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

    [application registerForRemoteNotifications];
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability |
        UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
6
0

The method registerForRemoteNotificationTypes: is depricated from iOS 8.0. Since you are compiling using iOS 8.1 SDK you will get the warning. It is an expected behavior and your application will work properly as your application will use registerForRemoteNotificationTypes: if and only if your iOS version is less than 8.0 where the method registerUserNotificationSettings: is defined.

If you need to avoid any depreciation warning you can use -Wno-deprecated-declarations flag to suppress the warning.

0

ok. I can understand your problem you have used deployment target 8.1. just change deployment target less than or equal to 7, otherwise remove else part because no need to define this in 8.1 target

2
  • i think, if deployment target is 8.1 then it supports only that iphone which uses 8.1 os...right?? Mar 11, 2015 at 9:13
  • @Bhavin yes ios 8.1 and above
    – SGDev
    Mar 11, 2015 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.