MUI - iOS嵌套h5項(xiàng)目,啟動(dòng),h5返回iOS原生框架的關(guān)鍵代碼

  • 按照MUI官方文檔操作,還要配合下面的代碼完成需求
js按鈕點(diǎn)擊事件里
關(guān)閉h5頁面,返回iOS原生框架
 var notiClass = plus.ios.importClass("NSNotificationCenter");
                                                       notiClass.defaultCenter().postNotificationNameobject("CloseWebAPP",null);

oc代碼
- (void)button3Click{
//啟動(dòng)h5工程
    NSString *pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/H586661F4/www"];
    pAppHandle = nil;
    //這里自己創(chuàng)建一個(gè)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{
    //不要在消息觸發(fā)的方法里關(guān)閉應(yīng)用需要使用異步的方式關(guān)閉APP
    [self performSelectorOnMainThread:@selector(classWebApp) withObject:nil waitUntilDone:NO];
}

- (void)classWebApp{
    //調(diào)用AppManager的方法關(guān)閉應(yīng)用
    [[PDRCore Instance].appManager end:pAppHandle];
    //需要把h5所在的頁面從主View中移除   我這樣直接把h5所在的頁面的父view置為nil
    for (UIView *subviews in [self.view subviews]) {
        if (subviews.tag==22) {
            [subviews removeFromSuperview];
        }
    }
    
    
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,741評論 25 709
  • MUI背景介紹 MUI是一套前端框架,由DCLOUD公司研發(fā)而成,提供大量H5和js語言組成的組件,大大提高了開發(fā)...
    jackzhouyu閱讀 29,889評論 2 76
  • Mac下忘記Mysql的root用戶密碼的解決方法 作者:開心程序 字體:[[增加](javascript:tur...
    ChangeAndChoice閱讀 616評論 0 0
  • 女神和我。 她是我的從小心目中的女神,長得白凈秀氣,氣質(zhì)清新脫俗,喜歡看書寫作,小時(shí)候我們總是一起玩。 她在聽范曉...
    LisGrocery閱讀 249評論 0 1
  • 經(jīng)常記起《金剛經(jīng)》里的一句話:凡所有相皆是虛妄,若見諸相非相,則見如來。這句說透了佛法根本核心的一句話,很早...
    馬嘉儷閱讀 566評論 0 0

友情鏈接更多精彩內(nèi)容