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

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
  • Are you sure that you have also as deployment target ios7 or lower? than make a clean build and build again – Andrea Mar 11 '15 at 08:40

4 Answers4

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:

Community
  • 1
  • 1
Huy Nghia
  • 996
  • 8
  • 22
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)];
}
Vaibhav Jhaveri
  • 1,579
  • 3
  • 28
  • 53
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.

abintom
  • 1,008
  • 7
  • 6
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

SGDev
  • 2,256
  • 2
  • 13
  • 29