我正在使用Objective C开发一个Xcode项目,该项目具有可选框架,这意味着只有在项目中链接/存在时,才会从该特定框架执行某些代码。我目前使用的框架是PassKit。我怎样才能做到这一点?是否有一些宏可以告诉框架链接或不是?像这样的东西,但它不起作用:
#if __has_include("PassKit.h") && __has_include(<PassKit.h>)
#import <PassKit/PassKit.h>
#endif
- (void)viewDidAppear:(BOOL)animated {
if ([PKPassLibrary class]) {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"PassKit Test"
message:@"PassKit is linked."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"Ok pressed...");
}];
[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];
}}
此外,我已在目标中将自动链接框架设置为否。感谢您的回答和帮助。
答案 0 :(得分:0)
#if __has_include(<PassKit/PassKit.h>) || __has_include("PassKit.h")
#define XXXPKTrigger
#endif
- (void)viewDidAppear:(BOOL)animated {
#ifdef XXXPKTrigger
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"PassKit Test"
message:@"PassKit is linked."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"Ok pressed...");
}];
[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];
#else
// do another logic
#endif
}