我正在使用handleOpenURL()进行自定义URL方案,以便从电子邮件中的链接启动我的应用程序.完美的工作,我可以根据链接中的URL参数在我的应用程序中执行操作. 问题是当我的应用程序冷启动
          问题是当我的应用程序冷启动(不在后台运行)时,handleOpenURL()似乎没有调用.是否有另一个处理程序可用于冷启动与已运行的实例?
要么
是否有一个我可以阅读的全局变量,它会告诉我调用URL是什么?我读了一下invokeString,但似乎从来没有设置过?
我正在使用PhoneGap 2.0
如果你仔细阅读应用程序上面的注释: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这个解决方案工作正常.
