0

尝试在我的应用程序中从WWDC 2012的SharedCoreData示例代码中实现 iCloud 同步,

addPersistentStoreWithType并在方法上崩溃。

- (BOOL)loadiCloudStore:(NSError * __autoreleasing *)error {
    BOOL success = YES;
    NSError *localError = nil;

    NSFileManager *fm = [[NSFileManager alloc] init];
    _ubiquityURL = [fm URLForUbiquityContainerIdentifier:nil];

    NSURL *iCloudStoreURL = [self iCloudStoreURL];
    NSURL *iCloudDataURL = [self.ubiquityURL URLByAppendingPathComponent:@"iCloudData"];
    NSDictionary *options = @{ NSPersistentStoreUbiquitousContentNameKey : @"iCloudStore",
                                NSPersistentStoreUbiquitousContentURLKey : iCloudDataURL };
    _iCloudStore = [self.psc addPersistentStoreWithType:NSSQLiteStoreType
                                          configuration:nil
                                                    URL:iCloudStoreURL
                                                options:options
                                                  error:&localError];
    success = (_iCloudStore != nil);
    if (success) {
        //set up the file presenter
        _presentedItemURL = iCloudDataURL;
        [NSFileCoordinator addFilePresenter:self];
    } else {
        if (localError  && (error != NULL)) {
            *error = localError;
        }
    }

    return success;
}

更新:崩溃日志:

Last Exception Backtrace:
0   CoreFoundation                  0x369f029e __exceptionPreprocess + 158
1   libobjc.A.dylib                 0x3b40697a objc_exception_throw + 26
2   CoreData                        0x37e0a35c -[NSPersistentStoreCoordinator initWithManagedObjectModel:] + 368
3   Dossier                         0x001541aa 0xd9000 + 504234
4   Dossier                         0x000db420 0xd9000 + 9248
5   UIKit                           0x353fcad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
6   UIKit                           0x353fc65e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
7   UIKit                           0x353f4846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
8   UIKit                           0x3539cc3c -[UIApplication handleEvent:withNewEvent:] + 1000
9   UIKit                           0x3539c6d0 -[UIApplication sendEvent:] + 68
10  UIKit                           0x3539c11e _UIApplicationHandleEvent + 6150
11  GraphicsServices                0x3686559e _PurpleEventCallback + 586
12  CoreFoundation                  0x369c567e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 10
13  CoreFoundation                  0x369c4ee4 __CFRunLoopDoSources0 + 208
14  CoreFoundation                  0x369c3cb2 __CFRunLoopRun + 642
15  CoreFoundation                  0x36936eb8 CFRunLoopRunSpecific + 352
16  CoreFoundation                  0x36936d44 CFRunLoopRunInMode + 100
17  UIKit                           0x353f3480 -[UIApplication _run] + 664
18  UIKit                           0x353f02fc UIApplicationMain + 1116
19  Dossier                         0x000db05c 0xd9000 + 8284
20  libdyld.dylib                   0x36a65b1c start + 0
4

0 回答 0