iOS Cordova 加载远程界面

  老大说,我们的项目要hybrid,要实现1、html能调用native;2、本地html调用本地html界面;3、能加载远程界面。。。。。

  因为我的项目是已有的(以下简称 项目),所以是要在已有的项目里加上cordova,只是在加载远程界面这个搞了好久,伤~~~

 

配置cordova

  人太懒,看这里的博客吧。或者自行搜索,网上一大把。

加载远程界面

  看了好几篇博客,都不行。

  a、ios cordova如何加载远程界面?

  b、Cordoval在iOS中的运用整理

  。。。。。。

  不行

然后我试着用$  cordova create Demo...命令创建一个demo(以下简称 demo),然后更改

@interface MainViewController : CDVViewController

@end



#import "MainViewController.h"

@implementation MainViewController

- (id)init
{
    self = [super init];
    if (self) {
        self.startPage = @"https://www.pgyer.com/ws9u";
    }
    return self;
}

@end

  run

  卧槽,这个怎么可以。。。。。。。。。。。

  然后就开着两个项目,看了这个到那个,反正是一把辛酸泪,关键是,demo里有两个www文件,我一开始比对的是最上面那个,哪都没错,哔了狗。后后来追踪代码才追到下面那个Staging目录。@#¥%……&*(

            

  好了,吐槽完毕,上正餐。

 

1、更改config.xml文件

  添加以下内容:

    <feature name="IntentAndNavigationFilter">
        <param name="ios-package" value="CDVIntentAndNavigationFilter" />
        <param name="onload" value="true" />
    </feature>

  这是我的完整内容:config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="xidx" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <feature name="LocalStorage">
        <param name="ios-package" value="CDVLocalStorage" />
    </feature>
    <feature name="HandleOpenUrl">
        <param name="ios-package" value="CDVHandleOpenURL" />
        <param name="onload" value="true" />
    </feature>
    <feature name="IntentAndNavigationFilter">
        <param name="ios-package" value="CDVIntentAndNavigationFilter" />
        <param name="onload" value="true" />
    </feature>
    <feature name="GestureHandler">
        <param name="ios-package" value="CDVGestureHandler" />
        <param name="onload" value="true" />
    </feature>
    <name>TEST</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
    <feature name="HTMLPlugin">
        <param name="ios-package" value="HTMLPlugin" />
    </feature>
</widget>

 

2、更改 CDVIntentAndNavigationFilter.m 文件

  修改- (void)parserDidStartDocument:(NSXMLParser *)parser方法;

- (void)parserDidStartDocument:(NSXMLParser*)parser
{
    // file: url <allow-navigations> are added by default
    self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://" , @"http://", @"https://", @"xxxxxschemes://"]];
    // no intents are added by default
    self.allowIntents = [[NSMutableArray alloc] init];
}

  如果需要响应scheme,就加上scheme,同时别忘了在info.plist里注册scheme

  

  

  效果图:

  

 

  附上demo:https://github.com/xuzixian/CordovaDemo

  有点乱,大家将就着看吧。

 

转载于:https://www.cnblogs.com/tufeibo/p/5830144.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值