1

iCloud で使用する Core Data データベースをセットアップしようとしています。基本的なことは理解しており、セットアップ方法に関するすばらしいチュートリアルに従いました。

データベースに接続できなかったというエラーが表示されます:

Unresolved error: Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1c5de2a0 {NSUnderlyingException=unable to open database file, NSSQLiteErrorDomain=14}, { NSSQLiteErrorDomain = 14; NSUnderlyingException = "unable to open database file"; }

永続ストアを返すコードは次のとおりです。

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil) {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CategoryModel.sqlite"];

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.
         Check the error message to determine what the actual problem was.


         If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

         If you encounter schema incompatibility errors during development, you can reduce their frequency by:
         * Simply deleting the existing store:
         [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

         * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
         [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

         Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    //  iCloud support
    //
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{        
        NSString *iCloudEnabledAppID = @"app.ident.ifier";
        NSString *dataFileName = @"CategoryModel.sqlite";

        NSString *iCloudDataDirectoryName = @"Data.nosync";
        NSString *iCloudLogsDirectoryName = @"TransactionLogs";

        NSFileManager *fileManager = [NSFileManager defaultManager];

        //  Create directory
        //
        NSURL *storeURL = [fileManager URLForUbiquityContainerIdentifier:nil];
        NSURL *dataFolder = [storeURL URLByAppendingPathComponent:iCloudDataDirectoryName];
        NSURL *dataFile = [dataFolder URLByAppendingPathComponent:dataFileName];

        BOOL isDirectory = YES;
        NSError *directoryError;

        if (![fileManager fileExistsAtPath:dataFolder.path isDirectory:&isDirectory]) {

            if (![fileManager createDirectoryAtURL:dataFolder
                       withIntermediateDirectories:YES
                                        attributes:nil
                                             error:&directoryError]) {
                NSLog(@"Create Directory Error: %@, %@", directoryError, directoryError.userInfo);
            }

        }

        NSLog(@"Data file: %@", dataFile.path);

        //  Set persistent store coordinator
        //
        NSError *pscError;

        NSLog(@"Store URL path: %@", storeURL.path);

        NSDictionary *options = @{ NSPersistentStoreUbiquitousContentNameKey : iCloudEnabledAppID,
                                   NSPersistentStoreUbiquitousContentURLKey : storeURL,
                                   NSMigratePersistentStoresAutomaticallyOption : @YES,
                                   NSInferMappingModelAutomaticallyOption : @YES};

        id result = [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                               configuration:nil
                                                                         URL:storeURL
                                                                     options:options
                                                                       error:&pscError];

        if (!result) {
            NSLog(@"Unresolved error: %@, %@", pscError, pscError.userInfo);
        }

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(iCloudChangesImported:)
                                                     name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
                                                   object:nil];
    });

    return __persistentStoreCoordinator;
}

編集

これが私の managedObjectModel メソッドです (CategoryModel は .xcdatamodeld の名前です)。

- (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CategoryModel" withExtension:@"momd"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return __managedObjectModel;
}

編集 2

ログで編集:

2013-03-01 22:33:37.658 Clueless[1268:3e07] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/.baseline/current.nosync/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.meta
Confused by: baseline.meta
2013-03-01 22:33:37.720 Clueless[1268:4d07] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE
Confused by: mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE
2013-03-01 22:33:37.731 Clueless[1268:4d07] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=
Confused by: kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=
2013-03-01 22:33:37.792 Clueless[1268:4903] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/.baseline/current.nosync/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.gcmodel
Confused by: baseline.gcmodel
2013-03-01 22:33:37.800 Clueless[1268:4903] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/.baseline/current.nosync/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.model
Confused by: baseline.model
2013-03-01 22:33:37.811 Clueless[1268:3e07] +[PFUbiquityLocation createUbiquityLocationForPath:withUbiquityRootPath:](821): CoreData: Ubiquity:  Unable to continue parse components of URL: /var/mobile/Library/Mobile Documents/app~ident~ifier/TransactionLogs/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip
Confused by: baseline.zip
2013-03-01 22:33:47.673 Clueless[1268:1103] Unresolved error: Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1e546570 {NSUnderlyingException=unable to open database file, NSSQLiteErrorDomain=14}, {
    NSSQLiteErrorDomain = 14;
    NSUnderlyingException = "unable to open database file";
}

編集 3

developer.icloud.com からファイルをダウンロードしようとすると、ダウンロードされず、メッセージが Safari コンソールに送信されますFailed to load resource: the server responded with a status of 409 (Conflict)

ファイルがアップロードされると、Safari コンソールにいくつかの警告が表示されます。

CloudOS:  Push notification has unknown topic: {"originating-dspsrid":"208020489","apsTopic":"5a5fc3a1fea1dfe3770aab71bc46d0aa8a4dad41","originating-peer":"4cfc48c6-a790-457c-6d80-02757cf88f07","originating-request":"ed063598-1501-40d7-aa53-0e305a2f0837"}
javascript-packed.js:132
Documents:  Local Rank has changed, updating the current visible Column.
    javascript-packed.js:132
CloudOS:  Push notification has unknown topic: {"originating-dspsrid":"208020489","apsTopic":"5a5fc3a1fea1dfe3770aab71bc46d0aa8a4dad41","originating-peer":"4cfc48c6-a790-457c-6d80-02757cf88f07","originating-request":"94622d8f-fe4d-4eb2-80b8-62f6fd6342cc"}
    javascript-packed.js:132
CloudOS:  Push notification has unknown topic: {"originating-dspsrid":"208020489","apsTopic":"5a5fc3a1fea1dfe3770aab71bc46d0aa8a4dad41","originating-peer":"4cfc48c6-a790-457c-6d80-02757cf88f07","originating-request":"5c73e9c2-952f-4452-b6a2-b86e7902c867"}
    javascript-packed.js:132
Documents:  Local Rank has changed, updating the current visible Column.

編集 [現在の番号は何でも]

永続ストアをログに記録する場合、NSLog(@"MOC: %@", self.managedObjectContext.persistentStoreCoordinator.persistentStores);

次の出力が得られます。

2013-03-02 13:57:38.241 Clueless[2221:907] MOC: (
    "<NSSQLCore: 0x1c5da560> (URL: file://localhost/var/mobile/Applications/[some long number which looks like it should be private]/Documents/CategoryModel.sqlite)"
)

unable to connect to databaseしたがって、ローカル永続ストアのみが存在するため、エラーが呼び出されたと推測しています

新しいエラー

Safe save failed for file, error: Error Domain=NSCocoaErrorDomain Code=512 "The file upload timed out." UserInfo=0x1c5cb220 {NSLocalizedDescription=The file upload timed out.}

編集 - ディレクトリのエラー

問題は、ディレクトリが作成されていないことにあると思います。

次のログは、ファイルを転送しようとすると、ディレクトリが存在しないことを示しています。これを修正できれば、iCloud は機能すると思います。

Had trouble moving baseline from: file://localhost/private/var/mobile/Library/Mobile%20Documents/app/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE to: file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip
Error: Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x1f5a0bd0 {NSFileNewItemLocationKey=file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE, NSFileOriginalItemLocationKey=file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip, NSUnderlyingError=0x1f591e20 "The operation couldn’t be completed. (Cocoa error 260.)", NSURL=file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip}
userInfo: {
    NSFileNewItemLocationKey = "file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE";
    NSFileOriginalItemLocationKey = "file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip";
    NSURL = "file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/baseline.zip";
    NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=260 \"The operation couldn\U2019t be completed. (Cocoa error 260.)\" UserInfo=0x1f5505b0 {NSURL=file://localhost/private/var/mobile/Library/Mobile%20Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE, NSFilePath=/private/var/mobile/Library/Mobile Documents/app~ident~ifier/Data.nosync/.baseline/app~ident~ifier/kySK3XJnAwbVqyiIiWGh3OEDvd2hq7_TYF6hZncfq24=/mobile.0543DD0C-48E2-5061-A42B-716AC22C02AE, NSUnderlyingError=0x1f5c38c0 \"The operation couldn\U2019t be completed. No such file or directory\"}";
}
4

0 に答える 0