2011-10-20 11 views
0

iCloudを使用するようにアプリケーションを更新していて、iOSデプロイメントターゲットを3.2のままにします。私は条件付きでiOS 5の呼び出しを遮蔽して、バックレベルのバージョンがクラッシュするのを防ぎます。私は何かが「発射が始まった」ログが掲載されていないため、コンパイル時に起こっていると思いNSMetaDataQueryを割り当てるときに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]; 

    } 


... 

...のように私のapplicationDidFinishLaunchingが見えます。条件付きブロックは正常に動作します。クエリのalloc initをコメントアウトすると、ブロックはiOS 5が実行されている場合にのみ実行されます。何か案は?

答えて

0

NSMetadataQueryではなくclsを使用する必要があります。

1

次のコードに置き換えます。このコードにより、

NSMetadataQuery *query; 
query = [[NSMetadataQuery alloc] init]; 

id query; 
query = [[cls alloc] init]; 
関連する問題