3

Any idea why startAccessingSecurityScopedResource always returns NO in the following callback of UIDocumentPickerViewController:

- (void)documentPicker:(UIDocumentPickerViewController*)in_documentPickerViewController didPickDocumentAtURL:(NSURL*)in_pickedDocumentAtURL
{
   BOOL l_bStartAccessingWorked = [in_pickedDocumentAtURL startAccessingSecurityScopedResource];
   ....

   void(^l_coordinateReadingAccessor)(NSURL*) = ^(NSURL* in_coordinateReadingURL)
   {
       ....
   };

   NSFileCoordinator* l_fileCoordinator = [[[NSFileCoordinator alloc] init] autorelease];
   NSError* l_error = nil;
   [l_fileCoordinator coordinateReadingItemAtURL:in_pickedDocumentAtURL
                                         options:0
                                           error:&l_error
                                      byAccessor:l_coordinateReadingAccessor];
   [in_pickedDocumentAtURL stopAccessingSecurityScopedResource];
}

I tried both my own App and Apple's NewBox example, tried on a few devices, and always get NO. However, the subsequent "coordinateReadingItemAtURL" works just fine.

Chang Kuang
  • 211
  • 1
  • 2
  • 6

1 Answers1

0

Very late, but I think NO means either access-denied or, more likely, the URL was not actually security-scoped. So, your call to stopAccessingSecurityScopedResource should be inside an if ( l_bStartAccessingWorked ) block.

I'm still learning this, so I could be mistaken. It fits my experience so far.

BruceL
  • 71
  • 3