2012-02-09 187 views
4

我需要在iCloud中創建具有某些文件的文件夾。嘗試以下操作:使用文件創建iCloud文件夾

NSString *folderName = [NSString stringWithFormat:@"folder_%@", [formatter stringFromDate:[NSDate date]]]; 

//iCloud folder 
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; 
NSURL *ubiquitousPackage = [[[ubiq URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:folderName]URLByAppendingPathComponent:@"file.txt"]; 
//NSLog(@"%@",ubiquitousPackage.relativePath); 

File *doc = [[File alloc] initWithFileURL:ubiquitousPackage]; 

[doc saveToURL:[doc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { 

    if (success) 
    { 

    } 
}]; 

它會返回錯誤:

Foundation called mkdir("/private/var/mobile/Library/Mobile Documents/6CVKW284XZ~com~cloudmy~rom/Documents/folder_20120209_194803/(A Document Being Saved By klp)"), it didn't return 0, and errno was set to 2.

+0

您沒有創建文件夾,而是沒有擴展名的文件。 – 2012-10-27 22:10:57

回答

0

您可能需要逃避空格字符文件名,如:

"(A\ Document\ Being\ Saved\ By\ klp)" 

+0

不工作。我在文件系統上創建了目錄folder_20120209_194803,並保存好。但現在我無法獲得文件夾。 – 2012-02-12 16:07:32

+0

你嘗試過[這個例子嗎?](https://github.com/lichtschlag/iCloudPlayground) – verec 2012-02-13 19:36:45