0
我需要保存在其上的應用程序創建的目錄中的一些圖片,這裏是我所保存的代碼創建目錄,並設置完全權限目的C不能寫入文件目錄的權限問題
NSFileManager* manager = [NSFileManager defaultManager];
SnapDir = [AssetPath stringByAppendingPathComponent:@"ScreenCaptures"];
if (![manager fileExistsAtPath:AssetWatchSnapDir isDirectory:&isDirectory] || !isDirectory)
{
NSError *error = nil;
[manager createDirectoryAtPath:SnapDir
withIntermediateDirectories:NO
attributes:nil
error:&error];
if (error)
NSLog(@"Error creating directory snap path: %@", [error localizedDescription]);
else {
NSError *error1;
[manager setAttributes:@{ NSFilePosixPermissions : @0777 }
ofItemAtPath:SnapDir error:&error1];
}
}
[[NSUserDefaults standardUserDefaults] setObject:SnapDir forKey:@"AssetSnap"];
現在圖像png格式一樣,
SnapDir = [[NSUserDefaults standardUserDefaults] objectForKey:@"AssetSnap"];
NSString* filepath = [SnapDir stringByAppendingPathComponent:filename];
NSError *error;
bool success = [pngRep writeToFile:filepath options:0 error:&error];
if (!success) {
NSLog(@"writeToFile failed with error %@", error);
}
能正常工作時,如果將圖像保存發生在目錄中創建的應用程序運行的同一個實例。這是我在應用程序中打開應用程序,創建目錄,然後保存。
凡當關閉應用程序並再次打開它,並嘗試保存圖像(使用存儲在NSUserDefaults
目的地路徑),它提供了關於權限問題下面的錯誤。
Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file 「2016_08_19_06_32_00.png」 in the folder 「ScreenCaptures」." UserInfo={NSFilePath=/Users/development/Documents/d/ScreenCaptures/
其實SnapDir是'NSString'類型,我找不到它的'path'或'relativePath'。 – Haris
你可以粘貼SnapDir的價值? –
是的,它在錯誤消息'/用戶/開發/文檔/ d/ScreenCaptures /' – Haris