Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: OSX Security-Scoped Bookmarks for App Store App



Permlink Replies: 1 - Last Post: Apr 27, 2017 1:04 PM Last Post By: Roy Woll
Mike Dixon

Posts: 29
Registered: 3/2/07
OSX Security-Scoped Bookmarks for App Store App
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 21, 2017 5:52 AM
Using XE8 Firemonkey, targeting MacOS.

I can find almost next to nothing on how to use Security-Scoped Bookmarks in an OSX App Store sandboxed app.

I know it has something to do with NSURL bookmarkDataWithOptions, but other than that I've found no sample code or documentation on this.

I'm trying to gain file permissions inside my sandboxed app after the user browses to the file via the Open Dialog. My database component (LiteDAC by DevArt) creates the file, but as soon as it tries to add a table it gets a permissions error. All the code works fine when the target is Normal, but has this issue when targeting the App Store.

Anyone have any tips?

Edited to add: Yes, I've set the proper entitlements, code signing, etc.

Edited by: Mike Dixon on Apr 21, 2017 5:54 AM
Roy Woll

Posts: 25
Registered: 11/26/06
Re: OSX Security-Scoped Bookmarks for App Store App
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2017 1:04 PM   in response to: Mike Dixon in response to: Mike Dixon
Mike,

I think the problem is that FireMonkey has not published all the necessary interfaces. For instance see the following

http://qc.embarcadero.com/wc/qcmain.aspx?d=113852

FireMonkey needs to surface all the capabilities/interfaces and let the developer community do the rest. This would also help 3rd party developers find generic solutions that work for all platforms.

I have been able to get the TOpenDialog to show files in sandbox (which did not work at first until I added entitlements), but I cannot seem to save the bookmarks. I have tried the following which crashes on my system at a later time, where LPath is the path that was opened by the dialog.

// Declarations
{$ifdef macos}
{$ifndef nextgen}
url: NSURL;
nsFilePath: NSString;
myBookmark: NSData;
err: NSError;
defaults: NSUserDefaults;
errmsg: string;
{$endif}
{$endif}

// Code
{$ifdef macos}
{$ifndef nextgen}
// Doesn't work right now
// save bookmark of file so we can open it next session
NSFilePath := StrToNSStr(LPath);
Url := TNSURL.Wrap(TNSURL.OCClass.fileURLWithPath(NSFilePath));
myBookmark:= Url.bookmarkDataWithOptions(
NSURLBookmarkCreationWithSecurityScope, nil, nil, @err);
if myBookmark<>nil then
begin
defaults := TNSUserDefaults.Wrap(TNSUserDefaults.OCClass.StandardUserDefaults);
defaults.setObject(myBookmark, StrToNSStr('iData'));
end;
{$endif}
{$endif}

-Roy

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02