Drag and drop into sandboxed App

I have an application that needs to save a file in the same location as the source file drag on the window of the application. The sandbox does not let me even right after you have checked "User selected File" ....

Thanks.

When dropping a file to your App, sandbox grants only access to this file. You can't even rename it. To write a new file in the same directory, use an NSOpenPanel to get write access to the directory.

eg:

 - (void)showGrantAccessForFolderOfFile:(NSURL *)urlOfFile
 {
    NSURL *urlToGrant = [urlOfFile URLByDeletingLastPathComponent];
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
    [openPanel setAllowsMultipleSelection:NO];
    [openPanel setCanChooseDirectories:YES];
    [openPanel setCanChooseFiles:NO];
    [openPanel setCanCreateDirectories:NO];
    [openPanel setDirectoryURL:urlToGrant];

    [openPanel setTitle:@"Grant Access To Folder"];
    [openPanel setMessage:@"Please grant access to the file’s folder"];
    [openPanel setPrompt:@"Grant Access"];

    // then run the panel as in documentation and handle errors
    // could also set a delegate and grey out other directories
    // store the sandboxed to access it later again
}
share | improve this answer
 
 
Thanks for your answer, it's works great... But is there a way to record the path in the application preferences and don't open an OpenPanel every time you launch the application ? –   Simon V.  Jan 13 at 8:36
 
This is a completely new question. See either documentation here:developer.apple.com/library/mac/documentation/Security/… "Security-Scoped Bookmarks and Persistent Resource Access" or search on StackOverflow for this. –   mahal tertin  Jan 13 at 13:54

Have you checked Apple's docs, in particular the Drag and Drop Programming Topics ?

Important: Although you can support dragging file paths, in general, you should avoid doing so unless you are certain that the destination app will never be run in an app sandbox. If you use an NSString, OS X has no way to know whether that string should be interpreted as a path; thus, OS X does not expand the destination app’s sandbox to allow access to the file or directory at that location.

Instead, use an NSURL, a bookmark, or a filename pasteboard type.

 
I saw that in OSX 10.9, after a drag and drop operation is finished, the sandbox only gives me read access to the dragged directory, even if I registered the view for NSURLPboardType dragged type. –   usain  May 28 at 15:41


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值