先把補充放在最前面html
2016年10月25號更新。正如老大所說,願望是美好的,現階段h5融合技術難點,咱們還無法解決,h5界面相比原生交互性能問題,管理類app操做設置太多。總結下Dcloud,可能不該該是下面這種方法,不能本地一個h5應用,而是應該直接把他當前webview使用就行了。下面能夠參考,也能夠不參考,可能有錯的地方,階段性棄用了,應該有段時間不去更新修改下面的啦。ios
2016年6月19號更新補充,因爲tabbar上須要這個模塊,而且發現runtime一直跑起的話,手機太熱,耗電嚴重。引擎本就是單例,因此控制器單例不適用和不使用了。git
感受因爲使用的是webview因此比較大。web
項目自己支持ios8以上,原生加載替換wkwebviewjson
6月26日,也不知道爲啥一樣方法進去導航欄控制器在視圖出現時是有的,加載完也是有的,而後h5那邊調用我這邊的退出的時候就沒了。不明緣由。你們有知道嗎?是hide之後會致使爲nil?app
總之無法解決,只是在首頁加個通知中心調用viewwillapear 。還必須延時2秒。否則仍是卡在首頁。好吧,挺糾結的這塊搞的。由於因此進去方法同樣,其餘三個模塊沒問題,不存在導航欄爲nil。還有一句是sdk好像最新的那一個,會死循環。本身能夠測試下。webapp
最後,去更新了下sdk 發現裏面有個iOS白皮書,之前還沒這個東西,坑比較多,如今參考那邊就行了。iphone
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異步
注意開發者在使用示例工程時建議不要把工程從SDK目錄裏挪出來,若是要移動工程能夠經過修改library search path ,framework search path 和head search path來解決報錯。
由於sdk太大,因此不建議拉進去的,所以放在目錄中,根據須要添加庫,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/Bundlesasync
中間那個能夠拉inc那個文件。我是拉進去編譯的。你也能夠拉進去不編譯。
根據這個文件Feature-iOS配置 other linker flags
同時須要注意下下面幾個,可能不同。
ui和個推sdk還有nativeui注意
oc代碼 - (void)button3Click{ //啓動h5工程 NSString *pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/H586661F4/www"]; pAppHandle = nil; //這裏本身建立一個view 代替官方代碼裏面的self.view view = [[UIView alloc] initWithFrame:self.view.bounds]; view.backgroundColor = [UIColor whiteColor]; view.tag = 22; [self.view addSubview:view]; [[PDRCore Instance] setContainerView:view]; pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"/html/goods/search.html" withArgs:nil withDelegate:nil]; [[[PDRCore Instance] appManager] restart:pAppHandle]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textClose:) name:@"CloseWebAPP" object:nil]; } - (void)textClose:(NSNotification *)not{ //不要在消息觸發的方法裏關閉應用須要使用異步的方式關閉APP [self performSelectorOnMainThread:@selector(classWebApp) withObject:nil waitUntilDone:NO]; } - (void)classWebApp{ //調用AppManager的方法關閉應用 [[PDRCore Instance].appManager end:pAppHandle]; //須要把h5所在的頁面從主View中移除 我這樣直接把h5所在的頁面的父view置爲nil for (UIView *subviews in [self.view subviews]) { if (subviews.tag==22) { [subviews removeFromSuperview]; } } }
js代碼
varnotiClass = plus.ios.importClass("NSNotificationCenter"); notiClass.defaultCenter().postNotificationNameobject("CloseWebAPP",null);
下面是我這部分的代碼,主要是根據上面的參考和官方的參考,使用的是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; //設置runtime根視圖的父親View [h5Engine setContainerView:_containerView]; //設置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模式 本地應用 PDRCoreApp* pAppHandle = nil; // 設置WebApp所在的目錄,該目錄下必須有mainfest.json NSString *pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/com.baobeigou.b2b/www"]; // 若是路徑中包含中文,或Xcode工程的targets名爲中文則須要對路徑進行編碼 NSString* pWWWPath2 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pWWWPath, NULL, NULL, kCFStringEncodingUTF8 )); // 這裏本身建立一個view 代替官方代碼裏面的self.view UIView* view = [[UIView alloc] initWithFrame:self.view.bounds]; view.backgroundColor = [UIColor whiteColor]; view.tag = 23; [self.view addSubview:view]; // 設置5+SDK運行的View [[PDRCore Instance] setContainerView:view]; // 傳入參數能夠在頁面中經過plus.runtime.arguments參數獲取.可不傳 // NSString* pArgus = @"id=plus.runtime.arguments"; // 建立app pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"index.html" withArgs:nil withDelegate:nil]; // 若是應用可能會重複打開的話建議使用restart方法 [[[PDRCore Instance] appManager] restart:pAppHandle]; } break; default:{ NSLog(@"輸入h5運行模式"); } break; }
能夠參考
返回按鈕http://www.jianshu.com/p/fff3f2ff99c9
其餘http://www.jianshu.com/p/d9050a1b765e
上文可能有點亂。
下文runtime只是指h5那個環境下的runtime。
h5環境的runtime關閉時越獄機可能會奔潰,有點坑沒有找到緣由。
爲了用戶體驗,點擊h5這個模塊不須要再等待幾秒,app開啓時直接跑起runtime了,記得單例下這個控制器,內存是增長了(不過好像退出界面關閉runtime的話,內存增長之後也沒明顯的減下來),一開始還擔憂審覈過不了,畢竟配置項太多,你們注意上線前須要去官網搜下審覈,manifest這邊配置不要被坑了。沒通知的話appdele那邊那些通知須要隱藏掉,否則審覈也過不了。還有因爲h5那邊帳號同步的緣由,因此帳號登出的時候,我關閉runtime,登陸成功的時候重啓runtime。解決了帳號不一樣步時,判斷不加載,而後卡死在h5環境的狀況下只能退出app。
關於優化(未實施):後臺模式時關閉runtime 切換前臺時開啓。iOS系統本身優化內存好像也是有效的。
需求(未實施),根據傳參判斷進不一樣頁面,因此記得控制器須要單例。還有返回頁面判斷下控制器類型。返回類型pop仍是dismiss,這部分只是涉及到項目中一個廣告頁是模態化去h5模塊的。