我正在使用phonegap。 目前在Android上我能利用我已经做了非常简单的功能,改变页面:使用插件更改当前页面
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
MainActivity ma = (MainActivity) cordova.getActivity();
ma.reload(args.getString(0));
return (true);
}
,并在MainActivity:
super.loadUrl("file:///android_asset/www/" + url, 1000);
但我新的目标C和iOs和我无法找到正确的关键字或答案的开头。 我'能有execute
功能相当于后来我不知道怎么去在MainActivity并重新加载页面
直到现在I'n我的插件,我有以下的代码,但它不工作:/
- (void)execute:(CDVInvokedUrlCommand*)command
{
//id message = [command.arguments objectAtIndex:0];
id message = @"buy/buy.html";
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:message]]];
}
编辑:
我已经尽量做到以下几点:
@implementation Redirect
- (void)execute:(CDVInvokedUrlCommand*)command
{
id message = [command.arguments objectAtIndex:0];
NSString* newUrl = message;
NSString* javaScript = nil;
NSString *jsCallBack = [[NSString alloc] initWithFormat:@"changeUrl('%@');", newUrl];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
javaScript = [pluginResult toSuccessCallbackString:jsCallBack];
[self writeJavascript:javaScript];
}
@end
,并在html:
window.changeUrl = function (url){
alert("ici");
navigator.app.loadUrl(url);
}
var Redirect= function(){
return cordova.exec(function(data){ alert(data);console.log("Success");}, function(){ console.log("Fail");},
"Redirect",
"execute",
[location.href]);
};
我敢肯定,这个插件被调用的时候,但如果我在changeUrl
功能没有把警报显示
感谢分享。 – Ross