0

我试图让我的应用程序通过 iCloud 将某些部分同步到多个设备。我在应用程序中启用了 iCloud 文档,并添加了 iCloud 容器。我按照向我展示的方式编辑了 Info.plist 文件。在我的代码中,创建了一个 plist 文件,我可以轻松地将其保存到设备的文档目录中,但每次尝试保存到 iCloud 时它都会崩溃。Ubiquitous 容器的日志始终显示(空)

id plist = [NSPropertyListSerialization dataWithPropertyList:self.theShow format:NSPropertyListXMLFormat_v1_0 options:nil error:nil];
        NSArray *paths = NSSearchPathForDirectoriesInDomains
        (NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *devotionals = [documentsDirectory stringByAppendingPathComponent:@"devotionals"];
        UITextField *textField = [alertView textFieldAtIndex:0];
        NSString *theName = textField.text;
        NSString *iCloudsave = [theName stringByAppendingString:@".plist"];
        //make a file name to write the data to using the documents directory:
        NSString *fileName = [NSString stringWithFormat:@"%@/%@.plist",
                              devotionals, theName];
        NSLog(@"%@", fileName);
        [plist writeToFile:fileName atomically:YES];
        
        
        
        
        NSURL* ubiq = [[NSFileManager defaultManager]URLForUbiquityContainerIdentifier:nil];
            NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:@"Documents"]  URLByAppendingPathComponent:iCloudsave];
        NSLog(@"UBIQ%@", ubiquitousPackage);
            
            [plist saveToURL:ubiquitousPackage forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success)
             {
                 if (success)
                 {
                     NSLog(@"Synced with icloud");
                 }
                 else
                     NSLog(@"Syncing FAILED with icloud");

             }];
4

0 回答 0