Created
November 27, 2012 05:53
-
-
Save rossmartin/4152604 to your computer and use it in GitHub Desktop.
Don't forget the code needed for Dropbox in your didFinishLaunchingWithOptions method. You can likely copy & paste the handleOpenURL function to your AppDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up) | |
*/ | |
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions | |
{ | |
// there will be more code in this method for your PhoneGap application | |
// code needed for Dropbox - Do not forget this | |
DBSession* dbSession = | |
[[[DBSession alloc] | |
initWithAppKey:@"Your-App-Key-Here" | |
appSecret:@"Your-App-Secret-Here" | |
root:kDBRootAppFolder] // either kDBRootAppFolder or kDBRootDropbox | |
autorelease]; | |
[DBSession setSharedSession:dbSession]; | |
// end of code needed for Dropbox | |
} | |
// this below happens while we are running in the background, or from within our own app | |
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url | |
{ | |
if (!url) { | |
return NO; | |
} | |
// calls into javascript global function 'handleOpenURL' | |
NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url]; | |
[self.detailViewController.webView stringByEvaluatingJavaScriptFromString:jsString]; | |
// all plugins will get the notification, and their handlers will be called | |
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; | |
// code below needed for Dropbox | |
if ([[DBSession sharedSession] handleOpenURL:url]) { | |
if ([[DBSession sharedSession] isLinked]) { | |
NSLog(@"App linked successfully with Dropbox !"); | |
// At this point you can start making API calls | |
NSString * jsCallBack = [NSString stringWithFormat:@"authDropboxFinished();"]; | |
[self.detailViewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack]; | |
// user linked with Dropbox, call authDropboxFinished() in dropbox.js JavaScript | |
} else { // else user didn't successfully link with Dropbox | |
NSLog(@"User didn't finish the Dropbox link process"); | |
} | |
//return YES; | |
} | |
// end of code needed for Dropbox | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment