phonegap - webViewDidFinishLoad没有被调用

时间:2012-10-01 17:34:46

标签: iphone ios cordova uiwebview

我正在使用Phonegap2.1。我的AppDelegate.m文件中有webViewDidFinishLoad方法。它曾经在以前的phonegap版本中被它自己调用。现在,它根本没有被调用。我需要在某个地方指派代表吗?

- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
{
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];
}
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];

return [ self.viewController webViewDidFinishLoad:theWebView ];
}

1 个答案:

答案 0 :(得分:1)

升级到2.1.0时,建议您注释掉所有该部分,因为它已弃用。使用cordova 2.1.0时,您提供的代码实际上对您没有任何帮助,所以如果您将其注释掉,那么您的应用应该可以正常工作。

http://iphonedevlog.wordpress.com/2012/09/24/phonegap-2-1-0-in-mac-os-x-mountain-lion-10-8-from-download-to-ios-app-store/

    #pragma UIWebDelegate implementation
    /*
    - (void) webViewDidFinishLoad:(UIWebView*) theWebView
    {
    // only valid if ___PROJECTNAME__-Info.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
    NSLog(@"DEPRECATED: window.invokeString - use the window.handleOpenURL(url) function instead, which is    always called when the app is launched through a custom scheme url.");
    NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
    [theWebView stringByEvaluatingJavaScriptFromString:jsString];
    }

   // Black base color for background matches the native apps
   theWebView.backgroundColor = [UIColor blackColor];

  return [super webViewDidFinishLoad:theWebView];
  }*/

将此部分取消注释会发出此警告:

 Classes/MainViewController.m:133:11: 'invokeString' is deprecated
 Classes/MainViewController.m:137:86: 'invokeString' is deprecated

您的应用程序运行正常,但发布有警告的产品并不理想。

除非你故意不把你的代码放到全世界去看

[CB-853]弃用window.invokeString - 使用window.handleOpenURL(url)代替

http://mail-archives.apache.org/mod_mbox/incubator-callback-commits/201207.mbox/%3C20120716205424.998B414A2D@tyr.zones.apache.org%3E