简体   繁体   中英

iphone iCloud app crashes when compiling on iOS 4

I'd like to use an iCloud, but when I compile the app on iOS 4.3 Simulator it crashes.

dyld: Symbol not found: _OBJC_CLASS_$_NSMetadataQuery

What should I do to make it working on iOS 3, 4, and 5?

my sulotion is:

Where have NSMetadataQuery change to id: ex

normal : - (void)loadData:(NSMetadataQuery *)query; change to: - (void)loadData:(id)query;

normal: @property (retain, nonatomic) NSMetadataQuery *query; change to: @property (retain, nonatomic) id query;

and check iCloud available:

if ([[NSFileManager defaultManager] respondsToSelector:@selector(URLForUbiquityContainerIdentifier:)]) {
        NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
        if (ubiq) {
            // Code for access iCloud here
        }
    }

When use NSMetadataQuery:

id _query = [[NSClassFromString(@"NSMetadataQuery") alloc] init];
// Some code here
[_query startQuery];

Have fun (^_^)

The usual way would be to compile it with iOS 5 SDK and setting the deployment target to the oldest iOS Version you'd like it to work with. It's up to you though to check at runtime on which classes and methods are available to the current system. A user on iOS 4 for example will not be able to use functions that only ship with iOS 5.

To check the availability of classes do:

if ( NSClassFromString(@"NSMetadataQuery") != nil ) {
  //do stuff with NSMetadataQuery here
}

To check the availability of methods do:

if ( [myObject respondsToSelector:@selector(doSomething)] ) {
  //call doSomething on myObject
}

这些API是与ios5一起启动的,因此您不能在模拟器4或更低的模拟器上运行它,但要发布,可以设置它应该支持的ios系列的最低部署目标。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM