Ios5 当我alloc init NSMetaDataQuery时,我的ApplicationIDFinishLaunching崩溃。。。。请帮忙

Ios5 当我alloc init NSMetaDataQuery时,我的ApplicationIDFinishLaunching崩溃。。。。请帮忙,ios5,icloud,Ios5,Icloud,我正在更新我的应用程序以使用iCloud,并希望我的iOS部署目标保持在3.2。我有条件地屏蔽任何iOS5调用,以防止任何后台版本崩溃。我的ApplicationdFinishLaunching看起来像 - (void)applicationDidFinishLaunching:(UIApplication *)application { NSLog(@"Launching Began..."); navigationController = [[UINavigationController

我正在更新我的应用程序以使用iCloud,并希望我的iOS部署目标保持在3.2。我有条件地屏蔽任何iOS5调用,以防止任何后台版本崩溃。我的ApplicationdFinishLaunching看起来像

- (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];

    }


...
-(void)applicationdFinishLaunching:(UIApplication*)应用程序{
NSLog(@“启动开始…”);
导航控制器=[[UINavigationController alloc]init];
navigationController.navigationBar.barStyle=UIBarStyleBlack;
[窗口添加子视图:navigationController.view];
[WindowMakeKeyandVisible];
//获取文档。
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsPath=[path objectAtIndex:0];
//设置主要客户
//解救卡利斯特的无政府主义者
NSString*archivePathFilename=[documentsPath stringByAppendingString:@”/carlist.archive];
self.maincalist=nil;
self.maincalist=[[NSKeyedUnarchiver unarchiveObjectWithFile:archivePathFilename]retain];
//如果操作系统版本=>5.0,则
NSString*reqSysVer=@“5.0”;
NSString*currSysVer=[[UIDevice currentDevice]systemVersion];
if([currSysVer比较:reqSysVer选项:NSNumericSearch]!=传感器解除搜索){
NSLog(@“在ApplicationIDFinish中启动iOS版本>5.0”);
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(carListDocumentStateChanged)名称:@“UIDocumentStateChangedNotification”对象:Nil];
NSString*carListDocumentURLString=[documentsPath stringByAppendingString:@”/mainCarListDocument.CLD“;
self.mainCalistDocumentUrl=[NSURL fileURLWithPath:carListDocumentURLString];//仅在此属性中设置本地保存位置
类cls=NSClassFromString(@“NSMetadataQuery”);
如果(cls){
NSMetadataQuery*查询;

query=[[NSMetadataQuery alloc]init];//您必须使用cls而不是NSMetadataQuery。

替换以下代码:

NSMetadataQuery *query;
query = [[NSMetadataQuery alloc] init];
根据该守则:

id query;
query = [[cls alloc] init];