2

I have been developing an OSX app with Delphi XE3 and running into various problems. The latest one is with the sanboxed version built for the Apple Appstore.

The user has to select an arbitrary folder and the app needs to get access to it. Since there is a problem with the OpenDialog, I had to turn to drag-drop functionality instead.
The user drags a folder to the app, the sandbox gives the app temporary access to it and all works properly.
To preserve the access to this folder when the app is restarted I have to use the so-called "security-scoped bookmarks"

I am having two issues with them:
1) How to add the "com.apple.security.files.bookmarks.app-scope" entitlement to an XE3 firemonkey app? It is not available in the Project Options->Entitlements. If I add it manually in the ".entitlements" file it gets overwritten when the app is built. So is there a way to add a custom entitlement that is not in the list in the project options?

2) To create the bookmark I should use the NSURL.bookmarkDataWithOptions method. I think it should be used like this, but I am not sure of the exact syntax:

var
  URL: NSURL;
  Err: NSError;
  Data: NSData;
...
URL := TNSURL.Create;
Data := URL.bookmarkDataWithOptions(NSURLBookmarkCreationWithSecurityScope, nil, @Err);
...

Maybe there should be a call to Wrap(...) instead of Create. I have not yet experimented with it, because it is pointless without the answer to issue 1).

It seems no one has written anything about these problems for Delphi, but I hope someone here has experience with that.

Thanks in advance.

Edit:
For problem 1) I tried to add edit manually the ".entitlements" file in the OSX32 folder and set it to read-only to prevent it from being overwritten. It was too easy to be true of course, because the linker complained that the file can not be modified...

Community
  • 1
  • 1
VGeorgiev
  • 491
  • 5
  • 16
  • Come on, am I always asking too hard questions :) Haven't received a working answer on any of them so far :) – VGeorgiev Feb 05 '13 at 11:31
  • Regarding 1) Does the complaint come as a ShowMessage-like window? Then maybe you can install `madExcept` and use the program `madTraceProcess` available in its `Tools` folder while the complaint is shown, and you find out how Embarcadero calls the part of the linker that troubles you. If it's just a text line in the output pane, this doesn't work though. – Gogowitsch Feb 05 '13 at 19:11
  • Thanks for the suggestion, it was an interesting one. It is not a message, but a line in the build log output. I could probably use other tools to debug and catch where the error is raised, but debugging and patching the compiler itself seems like an overkill. It would probably take me more time than to do some workaround in the application. – VGeorgiev Feb 06 '13 at 09:51

2 Answers2

0

OK, I finally found the way to manually add entitlements that are not available in the Project Options > Entitlements.

Instead of selecting the "App Store" build in the Project Manager you have to select a Normal release build and deploy the application as usual.
The application gets deployed in the PAServer scratch-dir as APP package. Inside this package there is an "Entitlements.plist" file, which is in XML format and can be edited with a text editor. It is quite obvious how to add new entitlements once you open the file.

After it is edited, the app has to be code-signed manually and a package has to be prepared. It is slightly more complicated than using the Delphi IDE, but there are instructions about it on the Embarcadero and Apple websites and it actually went without problems.

Still haven't tried the bookmarkDataWithOptions functions.

VGeorgiev
  • 491
  • 5
  • 16
0

An alternative could be to deactivate the checkbox for the entitlements-file in the deployment page.

But attention: Evry time you change between Build/Release or App Store/Normal, delphi activates the checkbox. That means you have to deactivate it again in the deplayment-page, to avoid the transfer of this file to the mac PC.

By the way: Do you have tryed meanwhile the StartAccessingSecurityScopedResource function? In the MacApi.Foundation unit the function is not declared in the NSURL interface.

Do you have found a way to use this function?

Kermit
  • 33,827
  • 13
  • 85
  • 121
  • Hi, welcome to Stack Overflow! You've posted an *answer* and a *question* in one. Since you have a separate question, you should [ask a new question](http://stackoverflow.com/questions/ask) with your specific issue. – Jesse Mar 17 '13 at 13:59
  • I've removed your questions from the answer, in order to prevent your answer from being removed (which seems helpful). – Jesse Mar 17 '13 at 14:00
  • @Jesse I don't think this user is trying to ask a *new* question; just that the user doesn't have enough rep to comment. I would recommend that the user move their question under this answer. – Kermit Mar 17 '13 at 14:04