Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以从iOS phonegap插件启动index.html_Ios_Cordova_Plugins - Fatal编程技术网

可以从iOS phonegap插件启动index.html

可以从iOS phonegap插件启动index.html,ios,cordova,plugins,Ios,Cordova,Plugins,首先让我描述一下我的场景:我有一个phonegap应用程序,它只是一个简单的视图,带有配置远程服务器地址的输入文本和一个启动程序btn,通过单击btn,它启动配置的托管应用程序并显示到本机webview中 但是,如果用户想要重新配置远程应用程序地址,我需要返回到基于本地的配置视图,因此我在托管应用程序中添加了btn。我不能简单地重新加载file:///blarblar/index.html 通过JavaScript,因为WebView(android和ios)对本地资源的访问限制 为了解决这个问

首先让我描述一下我的场景:我有一个phonegap应用程序,它只是一个简单的视图,带有配置远程服务器地址的输入文本和一个启动程序btn,通过单击btn,它启动配置的托管应用程序并显示到本机webview中

但是,如果用户想要重新配置远程应用程序地址,我需要返回到基于本地的配置视图,因此我在托管应用程序中添加了btn。我不能简单地重新加载file:///blarblar/index.html 通过JavaScript,因为WebView(android和ios)对本地资源的访问限制

为了解决这个问题,我尝试通过android中的本机插件进行实际的重新加载,如下所示:

 @Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    final CallbackContext ctxt = callbackContext;

    if (action.equals(ACTION_RELOAD)) {
        final Mobility act = (Mobility)cordova.getActivity();
        act.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                act.reloadMainView(); //--> this is calling super.loadUrl(Config.getStartUrl()); in MainActivity class
                ctxt.success("reloaded");
            }
        });

        return true;
    }

    callbackContext.error("Invalid action" + action + args);
    return false;
}
这在安卓系统中确实可以很好地工作。然后,我尝试开发出与iOS相同的版本,不幸的是,我在iOS本机开发方面非常有限,通过在Web上搜索大量资源,得出以下代码

#import "UiWrapper.h"
#import "../Classes/AppDelegate.h"
#import <Cordova/CDV.h>

@implementation UiWrapper

- (void) reload:(CDVInvokedUrlCommand*)command
{
    CDVPluginResult* pluginResult = nil;

    AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
    CDVViewController* topview = appDelegate.viewController;

    NSLog(@"test");
    [topview.webView stringByEvaluatingJavaScriptFromString:@"location='file:///var/mobile/Applications/A70D02B2-ED48-4918-9CF5-DA3953111636/SM%20Mobile%20Client.app/www/index.html'"];


    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"reloaded"];

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

@end
#导入“UiWrapper.h”
#导入“./Classes/AppDelegate.h”
#进口
@实现UiWrapper
-(void)重新加载:(CDVInvokedUrlCommand*)命令
{
CDVPluginResult*pluginResult=nil;
AppDelegate*AppDelegate=[[UIApplication sharedApplication]委托];
CDVViewController*topview=appDelegate.viewController;
NSLog(“测试”);
[topview.webView stringByEvaluatingJavaScriptFromString:@“位置=”file:///var/mobile/Applications/A70D02B2-ED48-4918-9CF5-DA3953111636/SM%20Mobile%20Client.app/www/index.html'"];
pluginResult=[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@“重新加载”];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@结束
它实际上不起作用,我认为原因是代码正在回调JavaScript以进行实际重新加载,这不会解决访问本地资源的限制。我需要的是直接在插件中加载index.html。我不知道如何在iOS中做到这一点


因此,我的问题是:是否可以从iOS插件加载index.html以及如何执行该操作的任何线索?

好的,最后找到如何在objective-c中将UIWebView重置为本地index.html

AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
CDVViewController* topview = appDelegate.viewController;

NSString* path = [[NSBundle mainBundle] pathForResource:@"www/index" ofType:@"html"];
NSURL* url = [NSURL fileURLWithPath:path];
NSURLRequest* request = [NSURLRequest requestWithURL: url];

[topview.webView loadRequest:request];

好的,想办法用纯客观的方式重新加载index.html。你制作了@RogerJin插件吗?是的,你可以试试。这是半年前做的。我不太确定它是否能与最新的cordova版本兼容。但要做到这一点应该很容易。:-)谢谢你@RogerJib。你的插件不能为我编译。原因是它试图找到流动性<代码>最终机动法案=(机动)cordova.getActivity()如何修复此问题?谢谢