PhoneGap.exec not working
I'm currently writing an HelloWorld plugin for PhoneGap,just to test his functionalities.I'm following the official documentation. I added to the onDeviceReady() function inside my Index.html page the following code:
window.plugins.testplugin.action(
function methodA() {
alert("A");
},function methodB() {
alert("B");
}
);
the objective-C module simply calls randomly one of the two callbacks. Unfortunately nothing happens. I've tried to call from inside the same onDeviceReady() some other PhoneGap API as the notification one,just to assure it's working, but nothing also in this case. It looks like the library is not working at all,but if I remove this:
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"></script>
the deviceready event is stopped from being fired. This means that somehow 开发者_StackOverflow社区the library is active but not working properly.
Any help?
thanks a lot
Problem Solved. Basically, the modification in the application delegate .m file I did in order to avoid the app from opening external links in Safari (in version 0.9.5):
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
*)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES
}
was, somehow, compromising the PhoneGap library functionalities. The correct approach is:
- (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 ];
}
}
I was suspecting that my PhoneGap.exec not working. So I sneaked in to the phonegap.js file. Then added some debugging alert. I was getting error message "ReferenceError: can't find variable PluginManager". If you are having the same problem then update the phonegap.js file. Mine was corrupted one.
精彩评论