Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Crashes when Home Button is pressed #13

Open
asifbilal786 opened this issue May 29, 2014 · 13 comments
Open

App Crashes when Home Button is pressed #13

asifbilal786 opened this issue May 29, 2014 · 13 comments

Comments

@asifbilal786
Copy link

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?

@moerter
Copy link

moerter commented Aug 5, 2014

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

@thomey
Copy link

thomey commented Aug 20, 2014

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

@chrishulbert
Copy link

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
Copy link

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

@chrishulbert
Copy link

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

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

@chrishulbert
Copy link

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

@TaPhuocHai
Copy link
Owner

Hi, Thanks a lot.

@MohamedGhebaji
Copy link

Thanks a lot you saved my day

@lcwei0521
Copy link

Thanks a lot !

pzhao5 added a commit to pzhao5/PHAirViewController that referenced this issue Dec 14, 2014
@SolomonBier
Copy link

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

@sunnywadhwa
Copy link

Thanks a lot. You save my day..

@rappier
Copy link

rappier commented Jul 15, 2015

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

@chrishulbert
Copy link

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 notifications@github.com 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
#13 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants