我正在更新我的应用程序以使用 iCloud,并希望我的 iOS 部署目标保持 3.2。我有条件地屏蔽任何 iOS 5 调用,以防止任何后级版本崩溃。我的 applicationDidFinishLaunching 看起来像......
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSLog(@"Launching Began...");
navigationController = [[UINavigationController alloc] init];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
// Getting the documentsPath.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
// Setting up the mainCarList
//unarchive the saved carlist
NSString *archivePathFilename = [documentsPath stringByAppendingString:@"/carlist.archive"];
self.mainCarList = nil;
self.mainCarList = [[NSKeyedUnarchiver unarchiveObjectWithFile:archivePathFilename] retain];
//if OS version => 5.0 then
NSString *reqSysVer = @"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) {
NSLog(@"in ApplicationDidFinishLaunching iOS version > 5.0");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(carListDocumentStateChanged) name:@"UIDocumentStateChangedNotification" object:Nil];
NSString *carListDocumentURLString = [documentsPath stringByAppendingString:@"/mainCarListDocument.CLD"];
self.mainCarListDocumentURL = [NSURL fileURLWithPath:carListDocumentURLString]; //sets the local save location only in this property
Class cls = NSClassFromString (@"NSMetadataQuery");
if (cls) {
NSMetadataQuery *query;
query = [[NSMetadataQuery alloc] init]; // <------- This crashes when running v4.3 iPhone sim.
/*
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
[self setDocumentMetaDataQuery:query];
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDataScope]];
[query setPredicate:[NSPredicate predicateWithFormat:@"%K == %@", NSMetadataItemFSNameKey, @"mainCarListDocument.CLD"]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering) name:NSMetadataQueryDidFinishGatheringNotification object:Nil];
BOOL didStart = NO;
didStart = [query startQuery];
if (didStart) {
NSLog(@"documentMetaDataQuery started");
}
else {
NSLog(@"error starting documentMetaDataQuery");
}
*/
[query release];
}
...
我认为在编译时发生了一些事情,因为没有发布“启动开始”日志。条件块正常工作。如果我注释掉查询的 alloc init,那么只有在 iOS 5 运行时才会运行该块。有任何想法吗?