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

后端 未结 18 1756
無奈伤痛
無奈伤痛 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:23
    exit(0);
    

    (must... type... 30 characters)

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

    a wrong NSLog statement will do it

    NSLog(@"%@",1);
    
    0 讨论(0)
  • 2020-12-12 12:24

    Add a gesture recognizer to a view that recognizes a 10 finger tap (5 fingers for iPhone as 10 can get a bit crowded). The GR has a method attached to it that executes anyone of the previously mentioned surefire ways to get your app to crash. Most users are not going to lay 10 fingers down on your app, so you're safe from the general user accidentally causing the crash.

    However you should be able to use something like Testflight or just deploying it to personal devices and test in the wild before ever submitting it to Apple. Having a forced crash could get your app rejected by Apple.

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

    You can also raise an exception:

    [NSException raise:NSInternalInconsistencyException
                format:@"I want to test app crashes!."];
    
    0 讨论(0)
  • 2020-12-12 12:26

    My current favourite:

    assert(! "crashing on purpose to test <insert your reason here>");
    

    A classic:

    kill( getpid(), SIGABRT );
    

    And some pr0n:

    *(long*)0 = 0xB16B00B5;
    

    All of them generate crashes captured by my crash reporting tool.

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

    How about a good old stack overflow :)

    - (void)stackOverflow
    {
        [self stackOverflow];
    }
    
    0 讨论(0)
提交回复
热议问题