PHAirViewController icon indicating copy to clipboard operation
PHAirViewController copied to clipboard

App Crashes when Home Button is pressed

Open asifbilal786 opened this issue 10 years ago • 13 comments

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?

asifbilal786 avatar May 29 '14 10:05 asifbilal786

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

moerter avatar Aug 05 '14 12:08 moerter

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...

thomey avatar Aug 20 '14 07:08 thomey

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

chrishulbert avatar Aug 22 '14 00:08 chrishulbert

Unfortunately GH won't allow me to attach the sample project. Attached here: http://s000.tinyupload.com/index.php?file_id=07458533194583357533

chrishulbert avatar Aug 22 '14 00:08 chrishulbert

Oh dear, i've found the problem. Simple mistake.

He's overridden 'dealloc' in a UIViewController category.

chrishulbert avatar Aug 22 '14 00:08 chrishulbert

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));
}

chrishulbert avatar Aug 22 '14 01:08 chrishulbert

Hi, Thanks a lot.

TaPhuocHai avatar Aug 22 '14 04:08 TaPhuocHai

Thanks a lot you saved my day

MohamedGhebaji avatar Nov 02 '14 13:11 MohamedGhebaji

Thanks a lot !

lcwei0521 avatar Dec 02 '14 09:12 lcwei0521

Wow @chrishulber method swizzling. Nice ! Was stuck on this too

SolomonBier avatar Dec 30 '14 08:12 SolomonBier

Thanks a lot. You save my day..

sunnywadhwa avatar Feb 19 '15 12:02 sunnywadhwa

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

rappier avatar Jul 15 '15 12:07 rappier

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 .

chrishulbert avatar Jul 15 '15 23:07 chrishulbert