1

I'm developing an iOS application and I want to get a specific function to run before my app crashes (if it ever does) as a security measure.

  • Is it possible to 100% of the time, run a function whenever the app is about to crash?
  • If not, in which situations can I and can't I get the function to run. I.e. it can run when it's an out of memory crash, but it can't run if it's a null reference exception for example.

Specifically, I am using Betfair's API and if the app crashes I want the app to first cancel all bets with Betfair before closing the application. I realise that this may in fact be impossible due to the nature of a crash stopping the entire app.

I'm using Xamarin and C# to develop the app (in case that matters!).

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ThinkOutside
  • 103
  • 10

2 Answers2

0

You can use NSSetUncaughtExceptionHandler and signal to catch most errors.

I've flagged a dupe answer which should have more details and discusses some edge cases that won't be caught without additional effort.

I don't know if C# changes the equation too dramatically. I haven't experimented with Xamarin.

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
0

And you're using

 try
 {
 }
catch(Exception ex)
 {
 }

around what could go wrong?

Dylan Meeus
  • 5,696
  • 2
  • 30
  • 49
  • Thanks Dylan. Yes I was using these, I just wanted to make sure that it would run the correct function if I had missed a try/catch somewhere. – ThinkOutside Nov 14 '13 at 22:53