2

iOS5に基づくCoreDataアプリにiCloudサポートを追加する作業をしています。最初のデバイスにアプリを問題なくインストールでき、データがiCloudにアップロードされます。テストのために2番目のデバイスにアプリをインストールしようとすると、次のエラーが発生します。

キャッチされなかった例外'NSInvalidArgumentException'が原因でアプリを終了しています、理由:'-[__ NSCFDictionary setObject:forKey:]:nilキーを挿入しようとしています'

これが私の関連するiCloudコードです:

// **注:このコードを自分の用途に適合させる場合は、次の変数を変更する必要があります。NSString * iCloudEnabledAppID = @ "com.strikelabs.iXercise";

    // ** Note: if you adapt this code for your own use, you should change this variable:        
    NSString *dataFileName = @"Xercise.sqlite";

    // ** Note: For basic usage you shouldn't need to change anything else

    NSString *iCloudDataDirectoryName = @"Data";
    NSString *iCloudLogsDirectoryName = @"Logs";
    NSFileManager *fileManager = [NSFileManager defaultManager];        
    NSURL *localStore = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:dataFileName];

    NSURL *iCloud = [fileManager URLForUbiquityContainerIdentifier:nil];

    if (iCloud) {

        NSLog(@"iCloud is working");

        NSURL *iCloudLogsPath = [NSURL fileURLWithPath:[[iCloud path] stringByAppendingPathComponent:iCloudLogsDirectoryName]];

        NSLog(@"iCloudEnabledAppID = %@",iCloudEnabledAppID);
        NSLog(@"dataFileName = %@", dataFileName); 
        NSLog(@"iCloudDataDirectoryName = %@", iCloudDataDirectoryName);
        NSLog(@"iCloudLogsDirectoryName = %@", iCloudLogsDirectoryName);  
        NSLog(@"iCloud = %@", iCloud);
        NSLog(@"iCloudLogsPath = %@", iCloudLogsPath);

        if([fileManager fileExistsAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName]] == NO) {
            NSError *fileSystemError;
            [fileManager createDirectoryAtPath:[[iCloud path] stringByAppendingPathComponent:iCloudDataDirectoryName] 
                   withIntermediateDirectories:YES 
                                    attributes:nil 
                                         error:&fileSystemError];
            if(fileSystemError != nil) {
                NSLog(@"Error creating database directory %@", fileSystemError);
            }
        }

        NSString *iCloudData = [[[iCloud path] 
                                 stringByAppendingPathComponent:iCloudDataDirectoryName] 
                                stringByAppendingPathComponent:dataFileName];

        NSLog(@"iCloudData = %@", iCloudData);

        NSMutableDictionary *options = [NSMutableDictionary dictionary];
        [options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
        [options setObject:[NSNumber numberWithBool:YES] forKey:NSInferMappingModelAutomaticallyOption];
        [options setObject:iCloudEnabledAppID            forKey:NSPersistentStoreUbiquitousContentNameKey];
        [options setObject:iCloudLogsPath                forKey:NSPersistentStoreUbiquitousContentURLKey];

        [psc lock];

        [psc addPersistentStoreWithType:NSSQLiteStoreType 
                          configuration:nil 
                                    URL:[NSURL fileURLWithPath:iCloudData] 
                                options:options 
                                  error:nil];

        [psc unlock];

私が知る限り、エラーはaddPersistentStoreWithType中に発生します。iPhone4SとiPad2でテストしています。アプリをインストールする順序に関係なく、エラーは常に2番目のデバイスで発生します。

どんな助けでもいただければ幸いです!

プログラムにiCloudエンティティがあり、プログラムがデバイスにインストールされている場合は常にエラーが発生するようです。

編集:これは修正されたようです。CoreDataのローカルストレージの場所のサフィックスとして.nosyncが必要です。

4

0 に答える 0