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

  有點亂,大家將就着看吧。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM