2012-02-09 8 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

フォルダは作成されませんでしたが、拡張子のないファイルが作成されました。 –

答えて

0

あなたはのように、自分のファイル名に空白文字をエスケープする必要があるかもしれません:

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

+0

動作しません。ファイルシステム上にディレクトリfolder_20120209_194803を作成し、すべて保存しました。でも、今はフォルダーを手に入れることができません。 –

+0

[この例は?](https://github.com/lichtschlag/iCloudPlayground)を試しましたか? – verec

関連する問題