我正在使用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 ];
}
答案 0 :(得分:1)
升级到2.1.0时,建议您注释掉所有该部分,因为它已弃用。使用cordova 2.1.0时,您提供的代码实际上对您没有任何帮助,所以如果您将其注释掉,那么您的应用应该可以正常工作。
#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)
代替