使用相机时切入后台报错:Thread1:EXC_BAD_ACCESS(code=1,address=0x1)解决办法之一

问题是ARC错误release的对象再次被release。

程序切入后台时不会走disapear方法

参考了http://songzengbin.github.io后总结如下

加入监听监听切入后台或进入前台,手动执行disappear

在init中

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterBackgorund:) name:UIApplicationDidEnterBackgroundNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];

    #pragma mark application  enterBackgorund enterForeground
-(void)enterBackgorund:(NSNotification *)notif
{
[self viewWillDisappear:YES];
}

-(void)enterForeground:(NSNotification *)notif
{
[self viewWillAppear:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
[self.mapView viewWillAppear];
self.isMapViewShowing = !self.mapView.hidden;
self.mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.mapView viewWillDisappear];
self.isMapViewShowing = NO;
self.mapView.delegate = nil; // 不用时,置nil
}
在dealloc中
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];

你可能感兴趣的:(GPUImage)