Search code examples
iphoneobjective-ciosdropboxdropbox-api

handOpenURL not being called for iPhone app using DropBox SDK


I am using MacOSX 10.6, and the Xcode simulator is 4.2, but after trying my best, handleOpenURL does not get called in my appdelegate.m file, where I have implemented it. I have followed all the instructions in the tutorial given in the DropBox site(DropBox Tutorial),

but, once a user allows my application to access, after loggin in from there dropbox account through safari, the control is redirected to my "Link with DropBox" view, i.e. the view from which the user gets the chance to log in,

The problem is, the handleOpenURL method is not called, and neither is the didfinishWithLaunchingOptions method called. I have seen in some posts in various forums related to the same topic, that if we implement the latter(didfinishWithLaunchingOptions) method, handleOpenWithURL will not called, is it so?

if not, can you please help me find out the error in my code.. I am a beginner in this field, and will really appreciate your help in this regard.

The following is the code snippet in the appdelegate.m file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
   NSLog(@"Inside didfinishwithoptions");
   DBSession* dbSession = [[[DBSession alloc] initWithAppKey:@"APP-KEY" 
                                                appSecret:@"APP-SECRET"
                                                     root:kDBRootAppFolder] // either kDBRootAppFolder or kDBRootDropbox
                        autorelease];
   [DBSession setSharedSession:dbSession];
   // Override point for customization after application launch.

   // Add the view controller's view to the window and display.
   [self.window addSubview:viewController.view];
   [self.window makeKeyAndVisible];

   return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 
{
    NSLog(@"Inside handleOpenURL");
    return NO;
}

Solution

  • I think that application:handleOpenURL: is not called when you set target to iOS 4.2 or later. Use application:openURL:sourceApplication:annotation: instead.

    More in UIApplicationDelegate docs.

    UPDATE:
    Did you double check your CFBundleURLTypes entry in your application's plist file? It should like something like that:

    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>DropBoxURLScheme</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>db-something</string>
        </array>
      </dict>
    </array>
    

    Than you init the session (note that above "something" part is used as app key):

    DBSession* dbSession = [[[DBSession alloc] initWithAppKey:@"something" appSecret:@"APP_SECRET" root:ACCESS_TYPE] autorelease];
    

    If above doesn't help, you must be doing wrong something else. Follow the DropBox's tutorial more carefully then.