- 按照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辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。