- 按照MUI官方文檔操作现横,還要配合下面的代碼完成需求
js按鈕點(diǎn)擊事件里
關(guān)閉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;
//這里自己創(chuàng)建一個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)系作者