我目前正在为 PhoneGap 编写一个 HelloWorld 插件,只是为了测试他的功能。我正在关注 official documentation . 我在 Index.html 页面的 onDeviceReady() 函数中添加了以下代码:
window.plugins.testplugin.action(
function methodA() {
alert("A");
},function methodB() {
alert("B");
}
);
Objective-C 模块只是随机调用两个回调之一。不幸的是什么也没有发生。我试图从同一个 onDeviceReady() 内部调用一些其他 PhoneGap API 作为通知 API,只是为了确保它正常工作,但在这种情况下也没有。看起来图书馆根本不工作,但如果我删除它:
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
deviceready 事件被停止触发。这意味着库以某种方式处于事件状态但无法正常工作。
有什么帮助吗?
非常感谢
最佳答案
问题已解决。 基本上,我在应用程序委托(delegate) .m 文件中所做的修改是为了避免应用程序在 Safari(版本 0.9.5)中打开外部链接:
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
*)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES
}
以某种方式损害了 PhoneGap 库的功能。正确的做法是:
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// add any other schemes you want to support, or perform additional
// tests on the url before deciding what to do -jm
if( [[url scheme] isEqualToString:@"http"] ||
[[url scheme] isEqualToString:@"https"])
{
[[UIApplication sharedApplication] openURL:url];
return YES;
}
else
{
return [ super webView:theWebView shouldStartLoadWithRequest:request
navigationType:navigationType ];
}
}
关于javascript - PhoneGap.exec 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951435/