Mac开发_解决使用NSURL无法访问桌面等文件的情况

  • 在使用NSURL遇到无法加载文件的情况时:
NSURL *ns_url = [NSURL fileURLWithPath:@"/Users/gc_mac/Desktop/earring.jpg"];
NSImage *image = [[NSImage alloc] initWithContentsOfURL:ns_url];
NSLog(@"NSImage == %@", image);
  • 请检查工程中的 .entitlements 文件,App Sandbox 属性参数是否被设置为YES,设置为 YES 则无法访问:
posted @ 2024-02-21 10:42  CH520  阅读(2)  评论(0编辑  收藏  举报