2017-07-25 29 views
17

我使用他UserNotification框架,它仅适用于iOS的10我声明,使用这个框架,到目前为止,我一直在做的可用性作为检查的方法如下:如何检查API可用性在Xcode 9

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

的XCode 9测试版刚刚发布,并使用此代码我得到一个警告

'UNNotificationContent' 是局部的:在iOS中推出10.0 注释 'handleWillPresentNotification:withCompletionHandler:' 与可用性属性为沉默

的问题是我怎么在Objective C代码注释此整个方法?我知道Xcode 9推出了

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

但我如何将整个方法(包括其签名)包裹在它呢?

欢呼

+0

这哪里是新@available语法记录? –

+2

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html – Jan

+0

你开发框架?看起来你需要为其他开发者进行注释。 – OzBoz

回答

32

回答我的问题:我需要使用NS_AVAILABLE_IOS宏如下标记方法:

-(BOOL)handleWillPresentNotification:(UNNotificationContent *)notificationContent NS_AVAILABLE_IOS(10_0); 
+1

我想'API_AVAILABLE(IOS(11.0))'比'NS_ABAILABLE_IOS'更通用,因为前者在铛头和定义后者在Foundation框架中定义。 – Itachi