What's a reliable way to make an iOS app crash?

后端 未结 18 1755
無奈伤痛
無奈伤痛 2020-12-12 11:47

I want to test my app\'s crash reporting out in the field by deliberately having it crash when the user performs a particular action that a real user is unlikely to do accid

相关标签:
18条回答
  • 2020-12-12 12:17

    abort(); causes abnormal termination… That is a crash.

    0 讨论(0)
  • 2020-12-12 12:18

    I use

    [self doesNotRecognizeSelector:_cmd]; 
    
    0 讨论(0)
  • 2020-12-12 12:19

    in Objective-C use C directly to cause a bad access

    strcpy(0, "bla");
    

    Note: while this works on any system I know -- in a future version of the C runtime OR the compiler this might not lead to a crash anymore. see Is null pointer dereference undefined behavior in Objective-C?)

    (in swift you would have to bridge to objC to do this)

    0 讨论(0)
  • 2020-12-12 12:21

    I would just kill the process normally:

    kill(getpid(), SIGKILL);
    

    So if you install a handler with signal you can also handle the crash, finishing to write opened files and these things.

    0 讨论(0)
  • 2020-12-12 12:22

    Try this:

    - (IBAction)Button:(id)sender
    {
        NSArray *array = [NSArray new];
        NSLog(@"%@",[array objectAtIndex:8]);
    }
    
    0 讨论(0)
  • 2020-12-12 12:23

    Most popular one - unrecognised selector crash:

    NSObject *object = [[NSObject alloc] init];
    [object performSelector:@selector(asfd)];
    

    Make sure you don't have -asdf method implemented in that class haha

    Or index beyond bound exception:

    NSArray * array = [NSArray array];
    [array objectAtIndex:5];
    

    And of course kill( getpid(), SIGABRT );

    0 讨论(0)
提交回复
热议问题