PHAirViewController
PHAirViewController copied to clipboard
App Crashes when Home Button is pressed
When i used UITableViewController in UINavigationStack, it worked fine in foreground. But loading a UITableViewController and then unLoad UITableViewController. Now pressing iPhone Home Button crashed the application with this error: [UITableViewController applicationWillSuspend]: message sent to deallocated instance.
Now, tell me what to do with this?
I can confirm that. I guess this is always when u show a ViewController with modal or custom segue. With push segue it works all fine. Also have problems with [xyz _parentviewcontroller] message sent to deallocated instance. (e.g. EKEventEditViewController)
What i found out: It crashes if u present a VC programatically. Call with segue, it all works fine
ModalViewController *modalVC = (ModalViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"modalTestVC"]; [self presentViewController:modalVC animated:NO completion:nil];
dismissViewController -> click Home Button -> crash
Same issue here triggered when using Facebook iOS SDK and app looses focus to perform connection to FB... With PHAirViewController included in the project it always crashes, works fine otherwise...
I'm getting the same issue. It's preventing notification removals. Here's my correspondence with the author on the subject:
Hi, Thanks for PHAirViewController, it's very pretty. However, it causes apps to crash, because somehow it prevents view controllers from removing themselves as system notification observers in the default dealloc. I've attached a sample project to illustrate. If you run the project as-is, then tap 'back' in the simulator, you can see in the log that there are no 'debug_removeObserver' entries in the log. However, if you remove the PHAirViewController.m file from the target, then re-run the app, tap 'back', you'll see 'debug_removeObserver' in the log. If you could help that'd be great. Thanks
Unfortunately GH won't allow me to attach the sample project. Attached here: http://s000.tinyupload.com/index.php?file_id=07458533194583357533
Oh dear, i've found the problem. Simple mistake.
He's overridden 'dealloc' in a UIViewController category.
OK Here's how you fix it. Search for:
@implementation UIViewController(PHAirViewController)
Remove this:
- (void)dealloc
{
self.phSwipeHander = nil;
}
Replace dealloc with this:
/// This is so that phSwipeGestureRecognizer doesn't create a swipe gesture in *every* vc's dealloc.
- (BOOL)phSwipeGestureRecognizerExists {
return objc_getAssociatedObject(self, SwipeObject) ? YES : NO;
}
- (void)ph_dealloc
{
if (self.phSwipeGestureRecognizerExists) {
self.phSwipeHander = nil;
}
[self ph_dealloc]; // This calls the original dealloc.
}
/// Swizzle the method into place.
void PH_MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
Method origMethod = class_getInstanceMethod(c, origSEL);
Method overrideMethod = class_getInstanceMethod(c, overrideSEL);
if (class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, overrideMethod);
}
}
/// Swizzle dealloc at load time.
+ (void)load {
SEL deallocSelector = NSSelectorFromString(@"dealloc"); // Because ARC won't allow @selector(dealloc).
PH_MethodSwizzle(self, deallocSelector, @selector(ph_dealloc));
}
Hi, Thanks a lot.
Thanks a lot you saved my day
Thanks a lot !
Wow @chrishulber method swizzling. Nice ! Was stuck on this too
Thanks a lot. You save my day..
Hello My Other Views have fixed the crash after doing this dealloc replacement but there in uncertain crash now at this giving EXCESS BAD ACCESS
if ([self.delegate respondsToSelector:@selector(heightForAirMenuRow)]) {
Class : PHAirViewController.m in reloadData function
You should open a new issue. Alternatively there are newer pods for achieving this menu these days, i'd consider looking for others.
On Wed, Jul 15, 2015 at 10:42 PM, Rappier [email protected] wrote:
Hello My Other Views have fixed the crash after doing this dealloc replacement but there in uncertain crash now at this giving EXCESS BAD ACCESS
if ([self.delegate respondsToSelector:@selector(heightForAirMenuRow)]) {
Class : PHAirViewController.m in reloadData function
— Reply to this email directly or view it on GitHub https://github.com/TaPhuocHai/PHAirViewController/issues/13#issuecomment-121604033 .