macos – 保存文件时的权限错误(沙箱)

macos – 保存文件时的权限错误(沙箱),第1张

概述我正在尝试将文件保存到路径中,在沙盒应用程序[OS X]中,但到目前为止我几乎每次尝试保存时都会收到错误.错误是…… Error saving: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “test.txt” in the folder “Testing”." UserI 我正在尝试将文件保存到路径中,在沙盒应用程序[OS X]中,但到目前为止我几乎每次尝试保存时都会收到错误.错误是……

Error saving: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “test.txt” in the folder “Testing”." UserInfo=0x1001f5e70 {NSfilePath=/Users/Seb/Desktop/Testing/test.txt,NSUnderlyingError=0x1001f5d70 "The operation Couldn’t be completed. Operation not permitted"}

我已将权限的“用户所选文件”设置为“读/写访问权限”.

我的代码..

Nsstring *saveLoc = [Nsstring stringWithFormat:@"%@/%@.txt",[[NSURL URLWithString:[[NSUserDefaults standardUserDefaults] valueForKey:@"saveURL"]] path],self.theWindow.Title];NSURL *saveURL = [NSURL fileURLWithPath:saveLoc];NSLog(@"Saving to: %@",saveLoc);NSError *err = nil;[self.textVIEw.string writetoURL:saveURL atomically:YES enCoding:NSUTF8StringEnCoding error:&err];if (err) {    NSLog(@"Error saving: %@",err);    [[NSAlert alertWithError:err] beginSheetModalForWindow:self.theWindow                                                       modalDelegate:nil                                                      dIDEndSelector:NulL                                                         contextInfo:nil];}

我究竟做错了什么?我该如何保存文件?

谢谢.

解决方法 要在沙箱外读/写文件,您必须获得用户对该文件或上述目录之一的访问权限.可以使用NSOpenPanel,NSSavePanel或拖放来获取访问权限.

应用程序终止后,对这些文件/目录的访问将丢失.

要永久访问用户选择的文件/目录,必须使用Security-Scoped Bookmarks.

总结

以上是内存溢出为你收集整理的macos – 保存文件时的权限错误(沙箱)全部内容,希望文章能够帮你解决macos – 保存文件时的权限错误(沙箱)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1006922.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存