說明:很久以前的文章官疲,理論上沒有多少參考價值(不確定)乏沸,后期官方sdk添加了白皮書集成方式决记,最后項(xiàng)目也棄用了這個sdk袜茧,紀(jì)念一下菜拓。 2017.10.10
以上為新增:
以下為歷史:
1 .參考鏈接
http://ask.dcloud.net.cn/docs/#http://ask.dcloud.net.cn/article/83
http://ask.dcloud.net.cn/docs/#http://ask.dcloud.net.cn/article/84
2 .特別注意這點(diǎn)。如果是新建項(xiàng)目可以根據(jù)那個demo來笛厦,但是如果是現(xiàn)有項(xiàng)目再添加這個環(huán)境的話就有點(diǎn)坑了纳鼎。
注意開發(fā)者在使用示例工程時建議不要把工程從SDK目錄里挪出來,如果要移動工程可以通過修改library search path 裳凸,framework search path 和head search path來解決報錯贱鄙。
因?yàn)閟dk太大,所以不建議拉進(jìn)去的,因此放在目錄中姨谷,根據(jù)需要添加庫逗宁,git上傳時忽略該文件夾,打開.gitignore 添加/SDK梦湘。
serach 下配置
Framework search paths
$(PROJECT_DIR)/SDK/libs/Release-iphoneos
$(PROJECT_DIR)/CloudStore/Share/Bundles
$(PROJECT_DIR)/SDK/libs/Release-iphonesimulator
Header search paths
$(SRCROOT)/SDK/inc recursive
library search paths
$(PROJECT_DIR)/SDK/libs/Release-iphoneos
$(PROJECT_DIR)/CloudStore/Share/Bundles
中間那個可以拉inc那個文件瞎颗。我是拉進(jìn)去編譯的件甥。你可以拉進(jìn)去不編譯。
3.最重要的配置
根據(jù)這個文件Feature-iOS配置 other linker flags
同時需要注意下下面幾個哼拔,可能不一樣引有。
ui和個推sdk還有nativeui注意
4.返回按鈕
http://www.reibang.com/p/fff3f2ff99c9
按照MUI官方文檔操作,還要配合下面的代碼完成需求
js按鈕點(diǎn)擊事件里關(guān)閉h5頁面倦逐,返回iOS原生框架
varnotiClass = plus.ios.importClass("NSNotificationCenter");
notiClass.defaultCenter().postNotificationNameobject("CloseWebAPP",null);
oc代碼- (void)button3Click
{//啟動h5工程
NSString*pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/H586661F4/www"];
pAppHandle =nil;
//這里自己創(chuàng)建一個view 代替官方代碼里面的self.viewview = [[UIView alloc]initWithFrame:self.view.bounds];
view.backgroundColor= [UIColorwhiteColor];
view.tag=22;
[self.viewaddSubview:view];
[[PDRCore Instance] setContainerView:view];
pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"/html/goods/search.html"withArgs:nilwithDelegate:nil];
[[[PDRCore Instance] appManager] restart:pAppHandle];
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(textClose:) name:@"CloseWebAPP"object:nil];
}
- (void)textClose:(NSNotification*)not{
//不要在消息觸發(fā)的方法里關(guān)閉應(yīng)用需要使用異步的方式關(guān)閉
APP[selfperformSelectorOnMainThread:@selector(classWebApp) withObject:nilwaitUntilDone:NO];
}
- (void)classWebApp{
//調(diào)用AppManager的方法關(guān)閉應(yīng)用[[PDRCore Instance].appManagerend:pAppHandle];//需要把h5所在的頁面從主View中移除 我這樣直接把h5所在的頁面的父view置為nil
for(UIView*subviewsin[self.viewsubviews]){
{if(subviews.tag==22) {
[subviews removeFromSuperview];
}
}
}
下面是我的控制器代碼譬正。模式為widget,webview和app都不使用檬姥。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textClose:) name:@"CloseWebAPP" object:nil];
//0為widget 1為webview 2為app模式曾我,
int jhb = 0;
switch (jhb) {
case 0:
{
//代理 基本是修改樣式
h5Engine.coreDeleagete = self;
//設(shè)置runtime根視圖的父親View
[h5Engine setContainerView:_containerView];
//設(shè)置5+Runtime ViewContoller
h5Engine.persentViewController = self;
[h5Engine showLoadingPage];
dispatch_async(dispatch_get_main_queue(), ^(void) {
[h5Engine start];
});
}
break;
case 1:
{
if (h5Engine != nil)
{
[h5Engine startAsWebClient];
NSString* pFilePath = @"http://www.baidu.com";
NSString* pFilePath = @"http://192.168.60.109/cloudstore/html/index.html";
CGRect StRect = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20);
PDRCoreAppFrame* appFrame = [[PDRCoreAppFrame alloc] initWithName:@"WebViewID1" loadURL:pFilePath frame:StRect];
[h5Engine.appManager.activeApp.appWindow registerFrame:appFrame];
[_containerView addSubview:appFrame];
[self.view addSubview:_containerView];
}
}
break;
case 2:{
// webapp模式 本地應(yīng)用
PDRCoreApp* pAppHandle = nil;
// 設(shè)置WebApp所在的目錄,該目錄下必須有mainfest.json
NSString *pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/com.baobeigou.b2b/www"];
// 如果路徑中包含中文健民,或Xcode工程的targets名為中文則需要對路徑進(jìn)行編碼
NSString* pWWWPath2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pWWWPath, NULL, NULL, kCFStringEncodingUTF8 ));
// 這里自己創(chuàng)建一個view 代替官方代碼里面的self.view
UIView* view = [[UIView alloc] initWithFrame:self.view.bounds];
view.backgroundColor = [UIColor whiteColor];
view.tag = 23;
[self.view addSubview:view];
// 設(shè)置5+SDK運(yùn)行的View
[[PDRCore Instance] setContainerView:view];
// 傳入?yún)?shù)可以在頁面中通過plus.runtime.arguments參數(shù)獲取.可不傳
// NSString* pArgus = @"id=plus.runtime.arguments";
// 創(chuàng)建app
pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"index.html" withArgs:nil withDelegate:nil];
// 如果應(yīng)用可能會重復(fù)打開的話建議使用restart方法
[[[PDRCore Instance] appManager] restart:pAppHandle];
}
break;
default:{
NSLog(@"輸入h5運(yùn)行模式");
}
break;
}
大家覺得還有問題的話可以參考下面的網(wǎng)址
http://www.reibang.com/p/d9050a1b765e
上文可能有點(diǎn)亂您单。
h5環(huán)境的runtime關(guān)閉時越獄機(jī)可能會奔潰,有點(diǎn)坑沒有找到原因荞雏。
為了用戶體驗(yàn)虐秦,點(diǎn)擊h5這個模塊不需要再等待幾秒,app開啟時直接跑起runtime了凤优,記得單例下這個控制器悦陋,內(nèi)存是增加了,一開始還擔(dān)心審核過不了筑辨,畢竟配置項(xiàng)太多俺驶,大家注意上線前需要去官網(wǎng)搜下審核,manifest這邊配置不要被坑了棍辕。沒通知的話appdele那邊那些通知需要隱藏掉暮现,不然審核也過不了。還有由于h5那邊賬號同步的原因楚昭,所以賬號登出的時候栖袋,我關(guān)閉runtime,登錄成功的時候重啟runtime抚太。解決了首頁登錄賬號卡死在h5環(huán)境的情況塘幅。優(yōu)化這邊未嘗試,可能我們可以后臺時關(guān)閉runtime尿贫。前臺切回