Re: Questions about sandboxing under Catalina

2020-01-10 Thread Steve Mills via Cocoa-dev
On Jan 10, 2020, at 08:41, Gabriel Zachmann via Cocoa-dev 
 wrote:
> 
> 
> Follow-up question:  is there a way to do that for screensavers?

That’s what happens when you go through NSOpenPanel and the user chooses a 
folder. Read that document that 2 of us have suggested.

Steve via iPad


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions about sandboxing under Catalina

2020-01-10 Thread Gabriel Zachmann via Cocoa-dev
>> 
>> So, is .../Containers/.../Data/Pictures linked to ~/Pictures automatically?
>   No.  The user has to give your app permission to see the contents of 
> ~/Pictures.
>   
> https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html
>  
> 
> 

Thanks.

Follow-up question:  is there a way to do that for screensavers?

Best regards, Gabriel


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions about sandboxing under Catalina

2020-01-10 Thread Steve Mills via Cocoa-dev
On Jan 10, 2020, at 07:36:03, Gabriel Zachmann via Cocoa-dev 
 wrote:
> 
> So, is .../Containers/.../Data/Pictures linked to ~/Pictures automatically?

Yes. That's under-the-hood stuff that you should mostly ignore. Pretend it 
doesn't exist. The OS will do what it needs to do.

> I am searching that directory (if the user did not specify any other 
> directory) for images using Spotlight.
> Apparently, Spotlight starts delivering images to my screensaver, and at some 
> point it gets killed or hangs.  I was wondering if that happens when 
> Spotlight tries to deliver images from the Photos database (which is also 
> stored in ~/Pictures).

I dunno. Is there some error returned?

> Do I have to do anything special to ensure that?
> Currently, I am using this very simple code:
> 
> - (IBAction) selectDirectory: (id) __attribute__ ((unused)) sender
> {
>NSOpenPanel *oPanel = [NSOpenPanel openPanel];
>long int result;
> 
>NSURL * url = [[oPanel URLs] objectAtIndex: 0];

You can also just use oPanel.URL if you only expect 1 file, otherwise you 
should loop through oPanel.URLs.

>NSString * aDir = [url path];

As long as you're not storing and reloading that path, but storing and loading 
security scoped bookmarks to urls instead, using a path created at runtime is 
fine. I prefer using urls instead, because that way you don't have to worry 
about some of this stuff. Most APIs that accept a path also have methods that 
use an NSURL. I suggest you use them.

>> and I store security-scoped bookmark data for each url they choose.
> 
> How do I do that? how would I use such url's?
> Could you explain this a bit further, or maybe you can provide a pointer 
> where I can read up on this?

Read this entire document - all sections. It explains the Container, security 
scoped bookmarks, etc. In fact, read it a couple times.

https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html

Then look for examples of using:

bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:
URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:
and
startAccessingSecurityScopedResource
stopAccessingSecurityScopedResource

The last two are important - always balance the use of one with the other.

--
Steve Mills
Drummer, Mac geek

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions about sandboxing under Catalina

2020-01-10 Thread Rob Petrovec via Cocoa-dev


> On Jan 10, 2020, at 6:36 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> Steve, thanks a lot for your response!
> 
>>> 
>>> In my screensaver, I try to search the Pictures directory in the user's 
>>> home.
>>> It is OK - for now - if my app cannot access any .photoslibrary, but I'd 
>>> like to pick up
>>> any other images in ~/Pictures.
>>> 
>>> I get the path using this line of code:
>>> [NSHomeDirectory() stringByAppendingPathComponent: @"Pictures/"]
>>> 
>>> However, when I print the actual path to the system log, it says it is 
>>> accessing this path:
>>> /Users/me/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures
>>> 
>>> Is this directory somehow linked to ~/Pictures ?
>>> Or how can I access the true ~/Pictures directory ?
>> 
>> That's how sandboxing works.
> 
> So, is .../Containers/.../Data/Pictures linked to ~/Pictures automatically?
No.  The user has to give your app permission to see the contents of 
~/Pictures.

https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html

—Rob


> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/petrock%40mac.com
> 
> This email sent to petr...@mac.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions about sandboxing under Catalina

2020-01-10 Thread Gabriel Zachmann via Cocoa-dev
Steve, thanks a lot for your response!

>> 
>> In my screensaver, I try to search the Pictures directory in the user's home.
>> It is OK - for now - if my app cannot access any .photoslibrary, but I'd 
>> like to pick up
>> any other images in ~/Pictures.
>> 
>> I get the path using this line of code:
>>  [NSHomeDirectory() stringByAppendingPathComponent: @"Pictures/"]
>> 
>> However, when I print the actual path to the system log, it says it is 
>> accessing this path:
>>  
>> /Users/me/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures
>> 
>> Is this directory somehow linked to ~/Pictures ?
>> Or how can I access the true ~/Pictures directory ?
> 
> That's how sandboxing works.

So, is .../Containers/.../Data/Pictures linked to ~/Pictures automatically?

I am searching that directory (if the user did not specify any other directory) 
for images using Spotlight.
Apparently, Spotlight starts delivering images to my screensaver, and at some 
point it gets killed or hangs.  I was wondering if that happens when Spotlight 
tries to deliver images from the Photos database (which is also stored in 
~/Pictures).


> My image-based screensaver works the same way, although the folders need to 
> be chosen by the user,

My screensaver has that feature, too.

> which ensures it has access to the files within,

Do I have to do anything special to ensure that?
Currently, I am using this very simple code:

- (IBAction) selectDirectory: (id) __attribute__ ((unused)) sender
{
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
long int result;

[oPanel setAllowsMultipleSelection: NO];
[oPanel setCanChooseDirectories: YES];
[oPanel setCanChooseFiles: NO];

[oPanel setDirectoryURL: [NSURL URLWithString: directoryLocation_]];
result = [oPanel runModal];
if ( result != NSModalResponseOK )
return;

NSURL * url = [[oPanel URLs] objectAtIndex: 0];
NSString * aDir = [url path];
...


>  and I store security-scoped bookmark data for each url they choose.

How do I do that? how would I use such url's?
Could you explain this a bit further, or maybe you can provide a pointer where 
I can read up on this?


Best regards, Gabriel

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com