【发布时间】:2011-12-11 16:31:37
【问题描述】:
我想使用 iCloud,但是当我在 iOS 4.3 模拟器上编译应用程序时它崩溃了。
dyld:未找到符号:_OBJC_CLASS_$_NSMetadataQuery
我应该怎么做才能让它在 iOS 3、4 和 5 上运行?
【问题讨论】:
标签: iphone compiler-errors icloud
我想使用 iCloud,但是当我在 iOS 4.3 模拟器上编译应用程序时它崩溃了。
dyld:未找到符号:_OBJC_CLASS_$_NSMetadataQuery
我应该怎么做才能让它在 iOS 3、4 和 5 上运行?
【问题讨论】:
标签: iphone compiler-errors icloud
我的建议是:
NSMetadataQuery 在哪里更改为 id: ex
正常 : - (void)loadData:(NSMetadataQuery *)query; 更改为:- (void)loadData:(id)query;
正常:@property (retain, nonatomic) NSMetadataQuery *query; 改为:@property (retain, nonatomic) id query;
并检查可用的 iCloud:
if ([[NSFileManager defaultManager] respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)]) {
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
// Code for access iCloud here
}
}
使用 NSMetadataQuery 时:
id _query = [[NSClassFromString(@"NSMetadataQuery") alloc] init];
// Some code here
[_query startQuery];
玩得开心(^_^)
【讨论】:
[[NSClassFromString(@"NSMetadataQuery") alloc] init]。你不能使用[NSMetadataQuery alloc]。
通常的方法是使用 iOS 5 SDK 编译它,并将部署目标设置为您希望它使用的最旧的 iOS 版本。不过,您可以在运行时检查当前系统可以使用哪些类和方法。例如,使用 iOS 4 的用户将无法使用仅随 iOS 5 提供的功能。
要检查课程的可用性,请执行以下操作:
if ( NSClassFromString(@"NSMetadataQuery") != nil ) {
//do stuff with NSMetadataQuery here
}
要检查方法的可用性,请执行以下操作:
if ( [myObject respondsToSelector:@selector(doSomething)] ) {
//call doSomething on myObject
}
【讨论】:
这些 API 已随 ios5 启动,因此您无法在模拟器 4 或更低版本上运行它,但发布时您可以设置它应该支持的 ios 系列的最小部署目标。
【讨论】: