Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iCloud文件存储/跨设备交换_Ios_Icloud_Document - Fatal编程技术网

Ios iCloud文件存储/跨设备交换

Ios iCloud文件存储/跨设备交换,ios,icloud,document,Ios,Icloud,Document,我正在尝试将数据存储到iCloud文档中,并在使用相同帐户登录的另一台设备上读取数据 我可以检测iCloud,将数据发送到iCloud,然后在同一台设备上读取。我可以从第二台设备检测到文件在那里,但当我尝试读取或复制文件时,会出现错误“nscocadomainerror-code 260” 文件存储代码: //CREATE FILE NSError *error; NSLog(@"string to write:%@",printString); NSURL *ubiq = [[NSFileM

我正在尝试将数据存储到iCloud文档中,并在使用相同帐户登录的另一台设备上读取数据

我可以检测iCloud,将数据发送到iCloud,然后在同一台设备上读取。我可以从第二台设备检测到文件在那里,但当我尝试读取或复制文件时,会出现错误“nscocadomainerror-code 260”

文件存储代码:

//CREATE FILE
NSError *error;

NSLog(@"string to write:%@",printString);
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

if (ubiq == nil) {
    return;
}
NSURL *cloudURL =[[ubiq URLByAppendingPathComponent:@"Documents" isDirectory:true] URLByAppendingPathComponent:@"CogwindInventory.txt"];
[printString writeToURL:cloudURL atomically:YES encoding:NSUTF8StringEncoding error:&error];
运行查询的代码:

self.backups = [[NSMutableArray alloc] init];
self.query = [[NSMetadataQuery alloc] init];
[self.query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K like 'CogwindInventory.txt'", NSMetadataItemFSNameKey];
[self.query setPredicate:pred];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(queryDidFinishGatheringRestore:)
                                             name:NSMetadataQueryDidFinishGatheringNotification
                                           object:self.query];
[self.CloudActivityIndicator startAnimating];
[self.query startQuery];

- (void)queryDidFinishGatheringRestore:(NSNotification *)notification {
    NSMetadataQuery *query = [notification object];
    [query disableUpdates];
    [query stopQuery];

    [self loadDataRestore:query];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query];

    self.query = nil;
}


- (void)loadDataRestore:(NSMetadataQuery *)query {
    [self.backups removeAllObjects];

    for (NSMetadataItem *item in [query results]) {
        NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
        //[self.backups addObject:url.lastPathComponent];
        [self.backups addObject: url.filePathURL];
    }
    if (self.backups.count > 0) {
        [self retrievefile];
    }
    [self OperationComplete];
}
执行读取操作的代码:

- (void) retrievefile
{
    NSError *error = nil;
    NSURL *ubiq = [self.manager URLForUbiquityContainerIdentifier:nil];

    if (ubiq == nil) {
        return;
    }
    NSURL *cloudURL =[self.backups objectAtIndex:0];
    NSArray *localtoken = [[NSString stringWithContentsOfURL:cloudURL encoding:NSUTF8StringEncoding error:&error] componentsSeparatedByString:@"\n"];

    if ((localtoken == nil) || (error !=nil)) {
        [self.CloudStatusText setText: @"Restore operation failed."];
        return;
    } else {
        [self.tokeninventory setPlayerInventoryNames:localtoken];
        [self.CloudStatusText setText: @"Restore operation successful. New inventory available"];
    }

}
这些设备是OS 8.1.1和OS 8.3。iCloud—文档在Xcode中启用,但在iCloudKit中未启用


谢谢你的帮助。谢谢。

在第二台iPad上又进行了一次测试。检查FileManager中的fileExistsAtPath,它显示它不存在,即使查询说它在那里。URL和路径似乎一致且正确。这是权限问题吗?好的。新数据。我更新了版本号,执行了清理,执行了归档,并验证了版本。这迫使资源调配配置文件使用新的内部版本号再次更新。Xcode每隔几分钟会定期暂停,我注意到Xcode版本是7.0.1。我不记得更新过7.0,但我可能已经更新过了。长话短说,它现在正在工作,虽然我必须给设备几分钟的时间来更新云,在商店选项完成后。