最近一个webView页面加载一个VR链接之后,在用友盟进行分享后,偶尔会在分享成功之后回调到app时出现闪退情况。
调试之后发现:如果h5加载完成之后分享就不会崩溃,没加载完成就分享就一定崩溃。
1、错误提示:
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient:
0x19cbfdfa0 <+0>: orr w8, wzr, #0x1
0x19cbfdfa4 <+4>: mov w9, #-0x21530000
0x19cbfdfa8 <+8>: movk w9, #0xbeef
-> 0x19cbfdfac <+12>: str w9, [x8]
0x19cbfdfb0 <+16>: ret
2、错误原因:
在分享跳转到微博时候,我的app进入后台,并且依然在进行绘制加载。
关于真机调试时按home键crash的问题
而苹果规定:如果尝试在后台执行OpenGL ES命令,应用程序将被终止。
例如:How to fix OpenGL ES application crashes when moving to the background
所以,就app就开始 “崩崩崩崩” 了。
3、解决方法:
通过通知来监控app是否进入后台和前台,在进入后台的时候禁止OpenGL,在进入前台后重新加载。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
- (void)appWillResignActive:(NSNotification *)notification {
// webView加载个空
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
// [self.webView stopLoading];
}
- (void)appDidBecomeActive:(NSNotification *)notification {
// 重新加载webView
if (self.url.length > 0) {
NSURL *requestUrl = [NSURL URLWithString:self.url];
NSURLRequest *request = [NSURLRequest requestWithURL:requestUrl];
[self.webView loadRequest:request];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}
4、不足之处:
分享回来之后会重新加载h5,效果并不是很好。
但是,我能想到的办法就是这样了,如果有更好的解决方法,请指教~