0

I want to make a small define for my project. That define should just execute a code if its above an ios version. It looks like this

#define IF_OS_8_OR_LATER(CODE)  \
   if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
   { \
      CODE; \
   } 

Its quite simple and working for this kind of stuff

IF_OS_8_OR_LATER(_locationManager.allowsBackgroundLocationUpdates = YES);

But now i want to extend this to avoid the "not available in deployment target" warning in my IDE (AppCode). I thought of extending it to this

#define IF_OS_8_OR_LATER(CODE)  \
_Pragma("clang diagnostic push") \
_Pragma("ide diagnostic ignored \"UnavailableInDeploymentTarget\"") \
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
    { \
        CODE; \
    } \
_Pragma("clang diagnostic pop")

But this is not working unfortunately. Any suggestions how to achieve this?

Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57

2 Answers2

0
  1. If you do not need this warning at all (in other files also), you can just disable this inspection in Preferences -> Inspections -> Objective-C -> General -> Usage of API unuavailable for deployment target.

  2. If you want to disable this warning for a single file - you can place cursor on the line, hit Alt+Enter (context menu will be opened), hit "right arrow" key on keyboard or the small triangle on the right of context menu option using mouse - it will open the context menu with "Supress for file" option. You can select this option and it will insert needed directives.

  3. If you want to do it by hand, the following snippet should work for you:

#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
#define IF_OS_8_OR_LATER(CODE)  \
   if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) \
   { \
      CODE; \
   }
#pragma clang diagnostic pop
-1
   You should write like this:

    #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |    UIUserNotificationTypeSound)];
    #endif

   Hope this helps you...
shiju86.v
  • 667
  • 5
  • 10