移动开发之——混合开发的那些坑

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

2016-03-07  本文已影响3953人  iOS_愛OS
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];
        }
    }
    
    
}

上一篇下一篇

猜你喜欢

热点阅读