简体   繁体   中英

iOS app crashes when home button is pressed (when app is suspended)

The app works fine, except that it cannot be suspended. Whenever I press the home button the application crashes with the following stack trace:

2014-03-27 12:00:31.413 ProjName[2598:60b] -[__NSCFDictionary animationForKey:]:
unrecognized selector sent to instance 0x17ee4cc0
2014-03-27 12:00:31.415 ProjName[2598:60b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFDictionary animationForKey:]: 
unrecognized selector sent to instance 0x17ee4cc0'
*** First throw call stack:
(0x2fc9cfd3 0x3a77fccf 0x2fca0967 0x2fc9f253 0x2fbee7f8 0x324caf01 0x324b9d83 0x3250e7b9  0x2fc5f1f1 0x2fbd357f 0x305bda3d 0x3253bdcd 0x324bdca5 0x324bd871 0x32521cc9 0x34acbaed 0x34acb6d7 0x2fc67ab7 0x2fc67a53 0x2fc66227 0x2fbd0f4f 0x2fbd0d33 0x34aca663 0x3251c16d 0x10f759 0x3ac8cab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

The end user never notices the crash when pressing the home button. However, when the app is supposed to be resumed, it is relaunched again. No error messages are shown, so the user probably think the application is working normally. What could be the problem here?

EDIT: This is where the exception is thrown (EXC_BAD_ACCESS code=1), in Supporting Files in main.m:

int main(int argc, char * argv[])
{
    @autoreleasepool {
       return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

EDIT2: I have now found what causes the problem, but Im still wondering why? If I create a UIView and add this in drawRect the problem occurs.

- (void)drawRect:(CGRect)rect {
    [self.layer setSublayers:nil];

    activityView = [[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityView.center=CGPointMake(200, 200);
    [activityView startAnimating];
    [self addSubview:activityView];
}

This error is possible to reproduce by adding a UIView with this drawRect like this. Can someone explain this behaviour?

- (void)viewDidLoad
{
   totalMeter = [[UIViewTest alloc] initWithFrame:CGRectMake(0, 80, 320.0, 320.0)];
   [self.view addSubview:totalMeter];

}
- (void)viewDidAppear:(BOOL)animated
{
   [totalMeter setNeedsDisplay];
} 
[__NSCFDictionary animationForKey:]: unrecognized selector sent to instance

问题是,当您的应用程序进入后台运行时,在某个地方,您会在类型字典值的值上调用animationForKey方法,但该方法无法实现。

If you use AFNetworking framework and including UIActivityIndicatorView+AFNetworking.h , I think this is an accusation. I had even happen in my work.

So, if you don't use UIActivityIndicatorView+AFNetworking.h , just remove it from your project, then rebuild your project, everything will be ok. wish you.

This is the issue in github AFNetworking issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM