cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DB Chooser failing in iOS9 - app not allowed to query for scheme

DB Chooser failing in iOS9 - app not allowed to query for scheme

Steve M.52
New member | Level 1

I'm using DBChooser in my app. The Dropbox app is installed on the device and updated. I'm using iOS 9.3.5.

I have registered schemes dbapi-1, dbapi-2 and dbapip-3 in LSApplicationQueriesSchemes in <app>-Info.plist. I have also registered db-<my_app_key> under URL Types (obviously, with my actual app key). Aside from adding dbapi-2, this is all unchanged from the previous version of the app in which everything was working.

So, what happens now is that when I run the following code:

- (void)executeDropboxImport

{

  [[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypeDirect

fromViewController:self

completion:^(NSArray *results) {

    if ([results count]) {

    NSDictionary *jsonDict = nil;

    DBChooserResult *file = [results firstObject];

    NSString *ext = [file.name pathExtension].uppercaseString;

    NSString *importFile = [NSString stringWithFormat:@"ImportFile.%@", ext];

    NSString *localPath = [NSTemporaryDirectory() stringByAppendingPathComponent:importFile];

// Make a local copy of the file

    if (file.size > 0 && ([ext isEqualToString:@"JSNST"])) {

    NSData *localFileData = [NSData dataWithContentsOfURL:file.link];

    [localFileData writeToFile:localPath atomically:YES];

   // ... do stuff with the data ...

}];

}

Watching the device's console log, when this method is called I see:

Sep 17 09:03:10 Steves-iPhone5 Dropbox[1369] <Warning>: -canOpenURL: failed for URL: "dbx-carousel://" - error: "(null)"
Sep 17 09:03:10 Steves-iPhone5 Dropbox[1369] <Warning>: -canOpenURL: failed for URL: "dbx-mailbox://" - error: "(null)"
Sep 17 09:03:11 Steves-iPhone5 Dropbox[1369] <Warning>: -canOpenURL: failed for URL: "dbx-carousel://" - error: "(null)"
Sep 17 09:03:11 Steves-iPhone5 Dropbox[1369] <Warning>: -canOpenURL: failed for URL: "dbx-carousel://" - error: "(null)"

Shortly followed by:


Sep 17 09:04:14 Steves-iPhone5 Dropbox[1369] <Warning>: -canOpenURL: failed for URL: "db-<my_app_key>://1/chooser?files=%5B%7B%22link%22%3A%22https%3A%2F%2Fdl.dropboxusercontent.com%2F1%2Fview%2Fcbm3aag0sip8eiz%2FStoryFlow%2520Docs%2FStoryFlow_ShotTypes.jsnst%22%2C%22bytes%22%3A1079%2C%22name%22%3A%22StoryFlow_ShotTypes.jsnst%22%2C%22is_dir%22%3Afalse%2C%22icon%22%3A%22https%3A%2F%2Fwww.dropbox.com%2Fstatic%2Fimages%2Ficons64%2Fpage_white.png%22%2C%22isDir%22%3Afalse%2C%22thumbnails%22%3A%7B%7D%7D%5D" - error: "This app is not allowed to query for scheme db-<my_app_key>"

 

It's finding the file okay. But why is it 'not allowed to query' when I have that scheme registered?

What happens is that the import just fails silently. Like I say, the file is seen but nothing is done with it.
...

16 Replies 16

Steve M.52
New member | Level 1

Okay, well I'm not using openURL, I'm using [NSData dataWithContentsOfUrl:file.link] as in the original message - included here again slightly edited. Like I said, this has worked fine until now...

- (void)executeDropboxImport // THIS IS FOR TESTING ONLY - SHOULDN'T NEED IT

{

  NSLog(@">>>> METHOD: executeDropboxImport <<<<<");

  [[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypeDirect fromViewController:self completion:^(NSArray *results) {

    NSLog(@">>>>> Importing after Dropbox selection");

    if ([results count]) {

      // we have a file

      NSLog(@">>>>> Count is greater than zero, so let's import <<<<<");

      NSDictionary *jsonDict = nil;

      DBChooserResult *file = [results firstObject];

      NSString *ext = [file.name pathExtension].uppercaseString;

      NSString *importFile = [NSString stringWithFormat:@"ImportFile.%@", ext];

      NSString *localPath = [NSTemporaryDirectory() stringByAppendingPathComponent:importFile];

      // Make a local copy of the file

      if (file.size > 0 && ([ext isEqualToString:@"JSNST"])) {

        NSData *localFileData = [NSData dataWithContentsOfURL:file.link];

         [localFileData writeToFile:localPath atomically:YES];

        NSError *jsonError;

        NSData *fileData = [NSData dataWithContentsOfFile:localPath];

         jsonDict = [NSJSONSerialization JSONObjectWithData:fileData options:NSJSONReadingMutableContainers error:&jsonError];

        if (jsonError) {

          // error stuff

         } else {

          // do stuff with the data

      }

  }];

}

Greg-DB
Dropbox Staff

You're not calling the handleOpenURL method in openURL as covered in the docs? I believe that is required, so I'm not sure why it would have worked before. Can you try adding it?

Steve M.52
New member | Level 1

Ah, sorry - you mean in the app delegate? Hmm, I see where there might be a problem here. I'm trying to discern between Dropbox and Airdrop imports so I'm now wondering if the test I'm using to determine it's Dropbox is valid:

 

- (BOOL)application:(UIApplication *)app

            openURL:(NSURL *)url

  sourceApplication:(NSString *)source

         annotation:(id)annotation

{

BOOL handled = NO;

DLog(@"source: %@", source);

DLog(@"annotation: %@", annotation);

 

if ([source isEqualToString:@"com.dropbox"]) {

if ([[DBChooser defaultChooser] handleOpenURL:url]) {

// This was a Chooser response and handleOpenURL automatically ran the

// completion block

handled = YES;

}

} else {

// Otherwise treat as Airdrop

NSString *filename = [url lastPathComponent];

NSString *ext = [filename pathExtension].uppercaseString;

NSDictionary *uInfo = @{AIRDROPPED_FILE_URL_KEY:url, @"filename":filename, @"ext":ext};

NSNotificationCenter *notificationCentre = [NSNotificationCenter defaultCenter];

if ([ext isEqualToString:@"SFPZ"] || [ext isEqualToString:@"FDX"]) {

if ([self.navController visibleViewController] == self.productionsViewController) {

NSNotification *notification = [NSNotification notificationWithName:AIRDROPPED_PRODUCTION_FILE_NOTIFICATION

object:self

  userInfo:uInfo];

[notificationCentre postNotification:notification];

handled = YES;

}

} else if ([ext isEqualToString:@"JSNST"] && [[self.navController visibleViewController] isMemberOfClass:[ZSShotTypeTableVC class]]) {

NSNotification *notification = [NSNotification notificationWithName:AIRDROPPED_SHOTTYPES_FILE_NOTIFICATION

object:self

  userInfo:uInfo];

[notificationCentre postNotification:notification];

handled = YES;

} else if ([ext isEqualToString:@"JSNL"] && [[self.navController visibleViewController] isMemberOfClass:[ZSLensTableVC class]]) {

NSNotification *notification = [NSNotification notificationWithName:AIRDROPPED_LENS_FILE_NOTIFICATION

object:self

  userInfo:uInfo];

[notificationCentre postNotification:notification];

handled = YES;

}

}

    return handled;

}

 

Greg-DB
Dropbox Staff

Yes, I meant in the app delegate. I'm not sure offhand exactly what source will be there. Is handleOpenURL:url getting called? 

Steve M.52
New member | Level 1

Well, it looks like we have our culprit. I just checked, and now the source is "com.getdropbox.Dropbox". I put that in as an alternative and it works!

This makes me a little nervous as to how reliable a test this is, but at least it's working for now. (I may just check for the presence of "dropbox" in the string somewhere - but that's for tomorrow. It's 22:30 here now...)

Thanks so much for your help.

Steve M.52
New member | Level 1

BTW, canOpenURL is still throwing up the "This app is not allowed to query for scheme db-..." warning. Just so you know. But the import is definitely working.

Greg-DB
Dropbox Staff

I'm glad to hear you got this sorted out. For reference though, I can't recommend relying on the source like that, since it isn't documented. Just calling the handleOpenURL method in any case should be safe though, since it won't take action if it doesn't seem to be a Chooser event. That's up to you of course though.

Also, these methods can be relatively noisy on iOS 9 and up unfortunately, but as long as the functionality is working it's safe to ignore those extra messages.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Steve M.52 New member | Level 1
What do Dropbox user levels mean?