2

I have an app and I want to target the new iOS 8.1 but, I also want people who have iOS 7 to be able to use my app. So for example for my push notifications, in my app delegate I have

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
} else {
    // Register for Push Notifications before iOS 8
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |
        UIRemoteNotificationTypeSound)];
}

To turn on push notifications for iOS 8 and iOS 7, but when I change my deployment target I get warnings saying this has been deprecated:

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

What is the best way to handle this? For submission to the app store and also personally I don't like to see warnings in my code.

Thanks for the help in advance.

EDIT

Here is a picture of the warnings I see my deployment target is iOS8.1 and not sure where to find my base SDK? Here is pic:

enter image description here enter image description here enter image description here enter image description here

iqueqiorio
  • 1,149
  • 2
  • 35
  • 78
  • 1
    Sometimes you just have to accept that there will be deprecation warnings when building for older versions of iOS. As long as they only happen during a production build, you can check over the list at every build to make sure nothing new has appeared. – Abhi Beckert Nov 14 '14 at 22:20
  • 1
    Please clarify what your Base SDK and your Deployment Target are set to. It should be "Latest (8.1)" and "iOS 7.0" respectively. If so, you will only get deprecation warnings for methods that were deprecated as of iOS 7.0. In that case, only use methods from iOS 7.0 or later. – rmaddy Nov 14 '14 at 22:41
  • In other words, if you are getting deprecation warnings about `registerForRemoteNotificationTypes` then your Deployment Target is not set to iOS 7 but is set to iOS 8. – rmaddy Nov 14 '14 at 22:42
  • @rmaddy where should I set the deployment target under the "Project" or under the "TARGETS" or both? – iqueqiorio Nov 14 '14 at 23:57
  • The target setting takes precedence over the project setting. – rmaddy Nov 15 '14 at 02:08
  • @rmaddy so what should i change? – iqueqiorio Nov 15 '14 at 19:24
  • Change either one. Just make sure that if you change the project level setting that the target level setting isn't overriding it. – rmaddy Nov 15 '14 at 19:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65010/discussion-between-iqueqiorio-and-rmaddy). – iqueqiorio Nov 15 '14 at 19:34
  • For your open questions from the chat please see the attached screenshots in my answer below – dogsgod Nov 21 '14 at 18:51

5 Answers5

4

Change your code as mentioned by orkenstein:

if ([application respondsToSelector:@selector(registerForRemoteNotificationTypes:)])
{

    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
}
else
{
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}

Next adjust your build settings
Set base SDK to latest:

Screenshot from Settings showing base SDK

... scroll down to Deployment and set deployment target to 7.0: Screenshot from Settings showing deployment target

Note that by changing the settings here you can (after a few seconds) directly see the warnings being turned on and off

With target = iOS 8.x Warnings on with target=8

With target = iOS 7.x Warnings off with target=7

Please disregard the SplashScreen warning ...

Community
  • 1
  • 1
dogsgod
  • 6,267
  • 6
  • 25
  • 53
  • When on the app store will it say under description that this app is targeted for iPhone 5,5s and 6? – iqueqiorio Nov 22 '14 at 17:16
  • That depends on the architectures you support. Do you have armv7 in the list? That should add the iPhone 4s and the iPad 2 to the list ... – dogsgod Nov 22 '14 at 19:51
  • project settings > build settings > target architecture should be something like "armv7, armv7s, arm64" to supporrt all devices from iphone4s to iphone6 – dogsgod Nov 23 '14 at 05:22
  • Do you have all the assets for iPhone4s included? Remember that it has another screen size. You will need other splash screen pictures... – dogsgod Nov 23 '14 at 18:32
  • Yes I have all that so I should have that set for iOS7 currently and it will still say tagerts for iPhone 6 in store? – iqueqiorio Nov 23 '14 at 18:57
  • Do you have an iPhone 6 connected during build? And if so, do you have the 'build active architecture' switch in the build settings set? – dogsgod Nov 23 '14 at 19:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65483/discussion-between-iqueqiorio-and-dogsgod). – iqueqiorio Nov 23 '14 at 22:22
1

We should kept deployment target 7.0, to work for iOS7. also use base SDK 8.1.

if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    // iOS 7 code here

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

else
    // Pre-iOS 7 code here

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


endif
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • and that will remove the warnings? and i have base sdks 8.1 and deployment iOS7 but in app store it doesn't say I am targeting iPhone 6? – iqueqiorio Nov 18 '14 at 17:18
  • iPhone 6 is a different matter. To support iPhone 6, you need to add iPhone 6 (and 6 Plus) launch images. – fishinear Nov 23 '14 at 00:21
1

I recommend use iOS 7.1 as min deployment target. I know its hilarious but thats how backward compatibility works with iOS 8.

khunshan
  • 2,662
  • 4
  • 28
  • 34
1
-(BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version

[a link] https://developer.apple.com/LIBRARY/ios/documentation/Cocoa/Reference/Foundation/Classes/NSProcessInfo_Class/index.html

I also found out about this in the docSet documentation for UIDevice

     UIDevice *dev = [UIDevice currentDevice];
     NSString* OSVer = [dev systemVersion];
     NSLog(@"%@",OSVer);

You could check the string if you had to since the isOperatingSystem is IOS 8 and above I would think that it would return no though on IOS ~7

  • a look here may also be helpful [a link]http://stackoverflow.com/questions/3339722/how-to-check-ios-version –  Nov 23 '14 at 19:23
  • I was reading that the IOS 8 @selector(isOperatingSystemAtLeas....) will crash an IOS7 device (not real smart I guess), but you can check if it responds to the selector and if it does you at least know you're using 8 or newer. Or use the UIDevice... mentioned above. –  Nov 24 '14 at 03:34
-1

Deprecation warnings are OK when you want to support lots of versions.
You need to check, if method is available. So test the selector:

if ([application respondsToSelector:@selector(registerForRemoteNotificationTypes:)]) {
  NSLog(@"It's ok");
} else {
  NSLog(@"Use another method");
}

UPDATE: If you still want to disable these warnings (not recommended), update your target settings:

enter image description here

orkenstein
  • 2,810
  • 3
  • 24
  • 45
  • So are you saying there is no way to get rid of these warnings? – iqueqiorio Nov 17 '14 at 13:52
  • @iqueqiorio, no. I must understand, that API changes, and deprecation warnings is the result of development. – orkenstein Nov 17 '14 at 16:48
  • @iqueqiorio, BUT! You able to disable deprecation warning for your target. – orkenstein Nov 17 '14 at 16:49
  • 1
    This is incorrect. Deprecation warnings only come if the method is deprecated in your specified deployment target. That is, when you are using something that is deprecated in all of the versions that you are supporting. – fishinear Nov 23 '14 at 00:26