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

后端 未结 18 1757
無奈伤痛
無奈伤痛 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:30

    I will go with:int raise(int sig);

    To get more info >man raise

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

    When working with RubyMotion I use this:

        n=Pointer.new ('c', 1)
        n[1000] ='h'
    
    0 讨论(0)
  • 2020-12-12 12:34

    Send a message to a deallocated object

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

    Since we all use Clang for iOS, this is fairly reliable:

    __builtin_trap();
    

    This has the benefit that it's designed for exactly this purpose, so it shouldn't generate any compiler warnings or errors.

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

    I think in Swift you could easily throw a fatal error:

    func foo() {
        fatalError("crash!")
    }
    

    It is actually even intended to use this feature in case something goes wrong in order to make the app crash.

    To avoid an if statement in a special case, you could use precondition, too. It's similar to assert, makes thus the intention (if wanted) pretty clear and is not removed in the final release as assert. It is used like precondition(myBoolean, "This is a helpful error message for debugging.").

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

    could try something like

    NSArray* crashingArray = [NSArray arrayWithCapacity:1];
    [crashingArray release];
    

    should crash on an EXC_BAD_ACCESS (might need to release it a second time but normaly it should crash like this already)

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