gpt4 book ai didi

objective-c - 如何在 Xcode 9 中检查 API 可用性

转载 作者:太空狗 更新时间:2023-10-30 03:13:29 25 4
gpt4 key购买 nike

我正在使用仅在 iOS 10 中可用的 UserNotification 框架。我正在声明一个使用此框架的方法,到目前为止,我一直在检查可用性,如下所示:

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

XCode 9 beta 刚刚发布,使用这段代码我收到警告

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

问题是我如何在 Objective C 代码中注释整个方法?我知道 Xcode 9 引入了

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

但是如何将整个方法(包括其签名)包装在其中?

干杯

最佳答案

回答我自己的问题:我需要使用 NS_AVAILABLE_IOS 宏标记方法,如下所示:

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

关于objective-c - 如何在 Xcode 9 中检查 API 可用性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45302614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com