CKAsset到NSData

时间:2015-08-14 09:42:48

标签: ios objective-c nsdata icloud cloudkit

我在CloudKit记录类型中的资产中存储了一些plist文件。我遇到了问题了解如何从iCloud下载pilst到文档目录文件夹。

CKDatabase *publicDatabase = [[CKContainer defaultContainer] publicCloudDatabase];
CKRecordID *record = [[CKRecordID alloc] initWithRecordName:@"Charts"];
[publicDatabase fetchRecordWithID:record completionHandler:^(CKRecord *musicRecord, NSError *error) {
    // handle the error
    if (error) {
        NSLog(@"%@", error);
    } else {
        NSLog(@"Plist Loaded %@", musicRecord.allKeys);
        NSData *Assetdata = [NSKeyedArchiver archivedDataWithRootObject:musicRecord.allKeys.lastObject];            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSString *documentsDirectory = [paths objectAtIndex:0];

        NSString *savePath = [documentsDirectory stringByAppendingPathComponent:@"charts"];

        [Assetdata writeToFile:savePath atomically:YES];
    }

任何帮助都得到了很多赞赏

0 个答案:

没有答案