2012-07-07 44 views
8

iOS iCloudNSInternalInconsistencyException (lỗi trong quá trình thực hiện chuỗi SQL 'INSERT INTO Y_UBMETA (YPEERID, YTRANSACTIONNUMBER))

Chấm dứt ứng dụng do ngoại lệ còn tự do 'NSInternalInconsistencyException', lý do:' lỗi trong quá trình thực hiện chuỗi SQL 'INSERT INTO Y_UBMETA (YPEERID, YTRANSACTIONNUMBER)

Lỗi chưa được giải quyết Lỗi miền = NSCocoaErrorDomain Code = 134312 "Lưu trữ siêu dữ liệu lưu trữ dường như đã không thành công, vui lòng thử thêm lại cửa hàng vào điều phối viên. Nếu không thành công, hãy di chuyển dữ liệu sang một thiết bị lưu trữ phổ biến mới cửa hàng." UserInfo = 0xdba5b80 {NSLocalizedDescription = Lưu trữ siêu dữ liệu phục hồi dường như đã thất bại, hãy thử thêm lại cửa hàng cho điều phối viên. Nếu điều đó không thành công, hãy di chuyển dữ liệu đến một kho lưu trữ liên tục mới.}, { NSLocalizedDescription = "Lưu trữ siêu dữ liệu lưu trữ dường như không thành công, vui lòng thử thêm lại cửa hàng vào điều phối viên. Nếu không thành công, hãy di chuyển dữ liệu đến cửa hàng liên tục mới phổ biến. ";

Làm cách nào để giải quyết vấn đề này? Coz rằng nó là một truy vấn nội bộ cho iCloud. Tôi đặt khối mã của tôi dưới đây của phương pháp tôi đã viết ..

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    NSLog(@"persistentStoreCoordinator:%@",[persistentStoreCoordinator_ description]); 
    if((persistentStoreCoordinator_ != nil)) 
    { 
        return persistentStoreCoordinator_; 
    } 

    NSLog(@"persistentStoreCoordinator:%@",[persistentStoreCoordinator_ description]); 
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataModel.sqlite"]; 

    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 


    NSPersistentStoreCoordinator* psc = persistentStoreCoordinator_; 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    
            
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
        NSFileManager *fileManager = [NSFileManager defaultManager]; 

        // Migrate datamodel 
        NSDictionary *options = nil; 

        // this needs to match the entitlements and provisioning profile 
        NSURL *cloudURL = [fileManager URLForUbiquityContainerIdentifier:nil]; 

        NSLog(@"cloudURL:%@",cloudURL); 

            //NSString* coreDataCloudContent = [[cloudURL path] stringByAppendingPathComponent:@"Data"];   
            
           cloudURL = [cloudURL URLByAppendingPathComponent:@"Data"];                                                                                                                                   

       // NSLog(@"coreDataCloudContent:%@",coreDataCloudContent); 


       //if ([coreDataCloudContent length] != 0 && [[defaults objectForKey:@"allMetadataFlag"] isEqualToString:@"YES"]) 
            
       if (cloudURL)//&& [[defaults objectForKey:@"allMetadataFlag"] isEqualToString:@"YES"]) 
            
        { 
            // iCloud is available 
           // cloudURL = [NSURL fileURLWithPath:coreDataCloudContent]; 

            NSLog(@"cloudURL:%@",cloudURL); 

            options = [NSDictionary dictionaryWithObjectsAndKeys: 
                       [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
                       [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
                       @"SecureAssistant.store", NSPersistentStoreUbiquitousContentNameKey, 
                       cloudURL, NSPersistentStoreUbiquitousContentURLKey,nil]; 
        } 
        else 
        { 
            // iCloud is not available 
            options = [NSDictionary dictionaryWithObjectsAndKeys: 
                       [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
                       [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil]; 
        } 
            NSError *error = nil; 
        [psc lock]; 
        if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) 
        { 
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
            abort(); 
        } 
        [psc unlock]; 

        dispatch_async(dispatch_get_main_queue(), ^{ 
            NSLog(@"asynchronously added persistent store!"); 
            [[NSNotificationCenter defaultCenter] postNotificationName:@"RefetchAllDatabaseData" object:self userInfo:nil]; 
        }); 

    }); 
    
   return persistentStoreCoordinator_; 
} 

Trả lời

0

tôi đã có cùng một vấn đề, nó xảy ra bởi vì tôi đã thay đổi các thuộc tính của DataModel từ Xcode, không phải từ ứng dụng của tôi bằng cách mã. tôi giải quyết điều này bằng cách xóa các tập tin SQLite từ iCloud và xóa các ứng dụng từ thiết bị sau đó xây dựng lại. Nó làm việc cho tôi.

Các vấn đề liên quan