MUI - iOS嵌套h5项目,启动,h5返回iOS原生框架的关键代码

  • 按照MUI官方文档操作,还要配合下面的代码完成需求
js按钮点击事件里
关闭h5页面,返回iOS原生框架
 var notiClass = 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;
    //这里自己创建一个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];
        }
    }
    
    
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,892评论 25 709
  • MUI背景介绍 MUI是一套前端框架,由DCLOUD公司研发而成,提供大量H5和js语言组成的组件,大大提高了开发...
    jackzhouyu阅读 29,869评论 2 76
  • Mac下忘记Mysql的root用户密码的解决方法 作者:开心程序 字体:[[增加](javascript:tur...
    ChangeAndChoice阅读 3,621评论 0 0
  • 女神和我。 她是我的从小心目中的女神,长得白净秀气,气质清新脱俗,喜欢看书写作,小时候我们总是一起玩。 她在听范晓...
    LisGrocery阅读 1,547评论 0 1
  • 经常记起《金刚经》里的一句话:凡所有相皆是虚妄,若见诸相非相,则见如来。这句说透了佛法根本核心的一句话,很早...
    马嘉俪阅读 3,474评论 0 0