How do I handle the custom URL scheme in PhoneGap for a cold start?

I use handleOpenURL () for a special URL scheme to launch my application from a link in an email. Works fine and I can do things in my application based on the URL parameters in the link.

The handleOpenURL () problem does not seem to cause a call when my application starts a cold start (does not work in the background). Is there any other handler that I can use for cold start compared to an already running instance?

OR

Is there a global variable that I can read that will tell me what the call url is? I read about invokeString but it never seems installed?

I am using Phonegap 2.0

+5
source share
2

: handleOpenURL, , , :

// this happens while we are running ( in the background, or from within our own app )
// only valid if Calinda-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url

, . , :

MainViewController.h

@interface MainViewController : CDVViewController
@property (nonatomic, retain) NSString *URLToHandle;
@end

MainViewController.m

- (void) webViewDidFinishLoad:(UIWebView*) theWebView 
{
     if (self.URLToHandle)
     {         
         NSString* jsString = [NSString stringWithFormat:@"window.setTimeout(function() {handleOpenURL(\"%@\"); },1);", self.URLToHandle];
         [theWebView stringByEvaluatingJavaScriptFromString:jsString];
     }
     [...]
}

- (void)dealloc
{
    self.URLToHandle = nil;
    [super dealloc];
}

@synthesize URLToHandle;

AppDelegate.m

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{   
    [...]
    self.viewController = [[[MainViewController alloc] init] autorelease];
    self.viewController.useSplashScreen = YES;
    self.viewController.wwwFolderName = @"www";
    self.viewController.startPage = @"index.html";
    self.viewController.view.frame = viewBounds;

    // Patch for handleOpenURL
    ((MainViewController *)self.viewController).URLToHandle = URLToHandle;

    [...]
}

, .

: , xcode. xcode , . xcode, .

+3

, - , , , URLToHandle AppDelegate (.h .m) , MainViewController.

AppDelegate.m

((MainViewController *)self.viewController).URLToHandle = URLToHandle;

to:

NSString* jsString = [NSString stringWithFormat:@"window.setTimeout(function() {handleOpenURL(\"%@\"); },1);", url];
((MainViewController *)self.viewController).URLToHandle = jsString;

URL AppDelegate MainViewController.

setTimeout , .

+3

All Articles