我正在使用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