Friday, September 20, 2019

#1 2019-06-20 02:44:42 am

Uwe
Member
Registered: 2018-03-29
Posts: 12

Is there a sandbox permissible way to check for presence of a folder?

Hi,

I have an app that uses alias as a way to check for presence of a folder in Application Support:
Definition of path:
tell application "System Events"
                set pathDriverFolder to path of (path to application support folder)
end tell

Testing of presence of folder:
set fullPath to pathDriverFolder & "Folder"
try
                fullPath as alias -- throws an error if folder doesn't exist
                --log "folder exists"

                on error
                --log "folder does not exist"
               
end try

That works fine but I gave it temporary entitlement for system events and the app got rejected (sort of understandably)

Is there a way to check for the presence of a folder that would be accepted by the App Store?

Thanks for your help,
Uwe

Offline

 

#2 2019-06-20 05:48:15 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5898

Re: Is there a sandbox permissible way to check for presence of a folder?

Have you tried the file manager? Something like:

Applescript:

NSFileManager's defaultManager()'s fileExistsAtPath:posixPath


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-06-21 06:04:55 am

Uwe
Member
Registered: 2018-03-29
Posts: 12

Re: Is there a sandbox permissible way to check for presence of a folder?

Brilliant - I keep forgetting my iOS derived knowledge, when I work with AppleScript - cheers Shane!

Now, I realise I used System Events also to modify a plist file that I created in the container. Guess I will have to use NSUserDefaults in the Sandbox ?

Best,
Uwe

Offline

 

#4 2019-06-21 06:58:42 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5898

Re: Is there a sandbox permissible way to check for presence of a folder?

Use NSPropertyListSerialization.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2019-06-22 12:31:20 pm

Uwe
Member
Registered: 2018-03-29
Posts: 12

Re: Is there a sandbox permissible way to check for presence of a folder?

Thanks again Shane! Works like a charm smile. I created an NSMutableDictionary and all is (seems) well. I think I should buy your book, if it is still available. Looks like I am asking obvious questions.
Now fingers crossed for the 2nd App Review ;-).

cheers,
Uwe

Update: ...it is approved smile . Thanks again, Shane!

Last edited by Uwe (2019-06-23 01:30:42 am)

Offline

 

#6 2019-06-26 04:48:23 am

Uwe
Member
Registered: 2018-03-29
Posts: 12

Re: Is there a sandbox permissible way to check for presence of a folder?

Oh noooooo

Somehow the app stopped writing to the plist file now.

I have the plist file in my app container.

I can read the plist file fine. I actually could also write to the file yesterday, I tested it many times in Xcode and the exported app.

As mentioned above, I submitted and it got approved but users came back, stating that no data were saved.
I checked in Xcode and now it does not save there either.

I am puzzled. I thought there is no requirement for an entitlement, if you write into the app container (and also cannot find one mentioned in the Apple guidance documents).

Update: ok - it seems to be a Sandbox issue, my code is fine. Sandbox off - I can write. Sandbox on - I can't. I am searching now for the entitlement for the container to write in there - really odd. Apple doc says, access to the app container is not regulated.User-selected file access entitlement does not work - and also should not work as it is for open panel type file access.

Update 2: To whom it concerns ....
Turns out that my definition of 'container' may not be what Apple's definition is:
So in Sandbox, I could not write to the 'Resources' of the app, which I would call a container - but I could read. So I left the starting plist there.
Then I created a path to the (most likely Apple) container of the app and checked for file presence upon start and if not present read out from the Resources file and wrote a first plist to that container (application support folder). And from then onwards only read plist from there.
All good in Xcode. Fingers crossed it will be good in life environment too.

Last edited by Uwe (2019-06-26 04:00:36 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)