21

I'm using he UserNotification framework that is available only in iOS 10. I am declaring a method that uses this framework and so far, I have been doing the check for the availability as follows:

@interface MyService : NSObject
 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
    -(BOOL)handleWillPresentNotification:(UNNotificationContent *)notificationContent;
#endif
@end

XCode 9 beta was just release and with this code I get a warning

'UNNotificationContent' is partial: introduced in iOS 10.0 Annotate 'handleWillPresentNotification:withCompletionHandler:' with an availability attribute to silence

The question is how do I annotate this in Objective C code the entire method? I know that Xcode 9 introduced the

if (@available(iOS 10, *)) {
    // iOS 10 ObjC code
}

but how do I wrap the entire method (including its signature) in it?

cheers

Dan Loewenherz
  • 10,879
  • 7
  • 50
  • 81
Jan
  • 7,444
  • 9
  • 50
  • 74
  • Where is this new @available syntax documented? – Berry Blue Sep 26 '17 at 04:56
  • 2
    https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html – Jan Sep 26 '17 at 07:43
  • Do you develop framework ? Looks like you need annotation for other developers. – OzBoz Sep 28 '17 at 17:32
  • yes I do. I need to support different versions of xcode for compilation and different versions of iOS for runtime ... – Jan Sep 28 '17 at 21:19

1 Answers1

40

to answer my own question: I need to mark the method using the NS_AVAILABLE_IOS macro as follows:

-(BOOL)handleWillPresentNotification:(UNNotificationContent *)notificationContent NS_AVAILABLE_IOS(10_0);
Jan
  • 7,444
  • 9
  • 50
  • 74
  • 3
    I think `API_AVAILABLE(ios(11.0))` is more generic than the `NS_ABAILABLE_IOS` as the former is defined in clang header and the latter is defined in Foundation framework. – Itachi Nov 20 '17 at 09:56