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: 

Re: Dropbox chooser completion handler not firing

Dropbox chooser completion handler not firing

Matthew W.8
New member | Level 1

I'm able to bring up my dropbox account, but when I pick a file, nothing happens, like the completion handler isn't firing. Here is what I have. I initialize with my own key because I'm using the Sync API as well, so I have two keys.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
  sourceApplication:(NSString *)source annotation:(id)annotation
{

    DBChooser *chooser = [[DBChooser alloc] initWithAppKey:@"[my key]"];

    if ([chooser handleOpenURL:url]) {
        // This was a Chooser response and handleOpenURL automatically ran the
        // completion block
        return YES;
    }
return NO;
}

and in my viewController.m

-(IBAction)didPressChooser:(id)sender {

    DBChooser *newChooser = [[DBChooser alloc] initWithAppKey:@"[my key]"];

        [newChooser openChooserForLinkType:DBChooserLinkTypeDirect
                                        fromViewController:self completion:^(NSArray *results)
         {
             if ([results count]) {

                 DBChooserResult *_result = results[0];
                 NSString *extension = [_result.name pathExtension];
                 if ([extension isEqualToString:@"m4a"] || [extension isEqualToString:@"wav"] || [extension isEqualToString:@"mp4"] ||[extension isEqualToString:@"mp3"]) {

                     NSURL *dropboxURL;

                     dropboxURL = _result.link;
                     DBFileName = _result.name;

                     NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
                     session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];
                    NSURLSessionDownloadTask *getFile = [session downloadTaskWithURL:dropboxURL];
                     [getFile resume];


                                                             }


                       }

         }];

}
5 Replies 5

Greg-DB
Dropbox Staff

[Cross-linking for reference: http://stackoverflow.com/questions/28390549/dropbox-chooser-completion-handler-not-firing ]

I believe the issue may be that you're essentially using two different Choosers in the different code snippets, i.e., by doing [[DBChooser alloc] initWithAppKey... twice. Can you try it with a shared Chooser object, e.g., by doing [[DBChooser alloc] initWithAppKey... just once and making the object available in both places ? (In the simple case, you would just use [DBChooser defaultChooser].)

Matthew W.8
New member | Level 1

Nothing yet. I added @property DBChooser *chooser; to my viewController.h, and in my viewController.m I put:

_chooser = [[DBChooser alloc] initWithAppKey:@"ag56efd9sjxt8vv"];

        [_chooser openChooserForLinkType:DBChooserLinkTypeDirect
                                        fromViewController:self completion:^(NSArray *results)
         {

             if ([results count]) {

                 DBChooserResult *_result = results[0];
                 NSString *extension = [_result.name pathExtension];
                 if ([extension isEqualToString:@"m4a"] || [extension isEqualToString:@"wav"] || [extension isEqualToString:@"mp4"] ||[extension isEqualToString:@"mp3"]) {

                     NSURL *dropboxURL;

                     dropboxURL = _result.link;
                     DBFileName = _result.name;

                     NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
                     session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];
                    NSURLSessionDownloadTask *getFile = [session downloadTaskWithURL:dropboxURL];
                     [getFile resume];
                                                             }


                       }

         }];

}

Then in my AppDelegate.h I imported the ViewController.h and put in @property ViewController *viewController;

and then in AppDelegate.m I have

if ([self.viewController.chooser handleOpenURL:url]) {

        return YES;
    }

Same thing happens. It doesn't return to fire the completion handler.

My permission is set for audio in the Dropbox app console. Not sure if that makes a difference

Matthew W.8
New member | Level 1

A correction on that last note. The permissions are simply Drop-ins. Thanks

Greg-DB
Dropbox Staff

Thanks for trying that and following up. Can you try it with just defaultChooser then? You actually don't need to have a separate Drop-ins app anymore anyway, since the key for your Sync API app can use Drop-ins too. (This wasn't always the case, which is why the documentation has the note about initWithAppKey.)

That is, as long as you have your Sync API app key registered in your URL scheme per the Sync API installation instructions, you can use defaultChooser without having to store and share a Chooser object manually:

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

and

[[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypeDirect

Matthew W.8
New member | Level 1

Thanks Greg. Yep, it does look like the single key I'm using for my sync works for the chooser as long as it's defaultChooser. I'll keep at it. Thanks!

Need more support?