標籤:
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 .注意官方介紹的這句。
注意開發人員在使用樣本工程時建議不要把工程從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/Bundles
中間那個可以拉inc那個檔案。我是拉進去編譯的。你也可以拉進去不編譯。
3.最重要的配置
根據這個檔案Feature-iOS配置 other linker flags
同時需要注意下下面幾個,可能不一樣。
ui和個推sdk還有nativeui注意
4.返回按鈕
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模組的。
iOS整合Dcloud