Permalink
Browse files

added invokeString + handleOpenUrl. These methods allow you to suppor…

…t your own custom protocol.

ex. myapp://some+params+here
  • Loading branch information...
1 parent ea8fd9b commit a492f0582641bd1a6729ca29e6d58d4bc5baec99 Jesse committed Mar 7, 2011
@@ -10,7 +10,13 @@
#import "PhoneGapDelegate.h"
@interface ___PROJECTNAMEASIDENTIFIER___AppDelegate : PhoneGapDelegate {
+
+ NSString* invokeString;
}
+// invoke string is passed to your app on launch, this is only valid if you
+// edit ___PROJECTNAME___.plist to add a protocol
+@property (copy) NSString* invokeString;
+
@end
@@ -11,6 +11,8 @@
@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate
+@synthesize invokeString;
+
- (id) init
{
/** If you need to do any extra app-specific initialization, you can do it here
@@ -19,12 +21,29 @@ - (id) init
return [super init];
}
-/**
- * This is main kick off after the app inits, the views and Settings are setup here.
- */
-- (void)applicationDidFinishLaunching:(UIApplication *)application
-{
- [ super applicationDidFinishLaunching:application ];
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+
+ NSArray *keyArray = [launchOptions allKeys];
+ if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil)
+ {
+ NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
+ self.invokeString = [url absoluteString];
+ NSLog(@"___PROJECTNAME___ launchOptions = %@",url);
+ }
+
+ return [super application:application didFinishLaunchingWithOptions:launchOptions];
+}
+
+// this happens while we are running ( in the background, or from within our own app )
+// only valid if ___PROJECTNAME___.plist specifies a protocol to handle
+- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
+{
+ // Do something with the url here
+ NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
+ [webView stringByEvaluatingJavaScriptFromString:jsString];
+
+ return YES;
}
-(id) getCommandInstance:(NSString*)className
@@ -40,6 +59,13 @@ -(id) getCommandInstance:(NSString*)className
*/
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
+ // only valid if ___PROJECTNAME___.plist specifies a protocol to handle
+ if(self.invokeString)
+ {
+ // this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
+ NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
+ [theWebView stringByEvaluatingJavaScriptFromString:jsString];
+ }
return [ super webViewDidFinishLoad:theWebView ];
}
@@ -50,7 +76,7 @@ - (void)webViewDidStartLoad:(UIWebView *)theWebView
/**
* Fail Loading With Error
- * Error - If the webpage failed to load display an error with the reson.
+ * Error - If the webpage failed to load display an error with the reason.
*/
- (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error
{
@@ -26,12 +26,25 @@
document.addEventListener("touchmove", preventBehavior, false);
*/
- function onBodyLoad()
+ /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
+ see http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
+ for more details -jm */
+ /*
+ function handleOpenURL(url)
{
+ // TODO: do something with the url passed in.
+ }
+ */
+
+ function onBodyLoad()
+ {
document.addEventListener("deviceready",onDeviceReady,false);
}
/* When this function is called, PhoneGap has been initialized and is ready to roll */
+ /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch.
+ see http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
+ for more details -jm */
function onDeviceReady()
{
// do your thing!

0 comments on commit a492f05

Please sign in to comment.