On 22 Jan 2014, at 02:46, koko <[email protected]> wrote:
> I believe I should use contentsOfDirectoryAtURL and then create a
> security-scoped bookmark for each file I am interested in and in this manner
> I will be able to read the files across launches of the app.
>
> On Jan 21, 2014, at 7:26 PM, koko <[email protected]> wrote:
>
>> In the code snippet below is it possible to read the files whose names are
>> in the NSArray contents?
>>
>>
>> if ( [url startAccessingSecurityScopedResource] )
Where did url come from? Presumably a bookmark, and since you expect it to be a
directory, it must be an application-scoped bookmark.
-startAccessingSecurityScopedResource will grant your app access to the
directory and all the files/folders etc. inside it (recursively).
>> {
>> NSFileManager *defaultManager = [NSFileManager defaultManager];
>> NSArray *contents = [defaultManager contentsOfDirectoryAtPath:[url
>> path] error:&error];
>> [url stopAccessingSecurityScopedResource];
Access is counter-based, so assuming you haven’t got any other calls to
-startAccessingSecurityScopedResource for the same location on the go, this
line of code has just cut off access.
Yes, you could first generate more bookmarks for each of the files inside the
directory, but that seems a weird thing to do for most use cases. Instead, just
keep access to the directory open until you’re finished with it.
>> }
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]