'App is closing' event?

I have a main view which saves state when it is closed or deactivated.
But if the app is shut down, (low power, deliberate closure, whatever) neither of these events are called and the data isnt saved.
The App class doesnt have a cancelclose or close() event I could tap into.

How do we save data before an app is closed?

I’d guess there’s notifications from iOS you could hook into with declares to know these things

see https://developer.apple.com/documentation/foundation/nsnotificationname?language=objc

The iOS AppDelegate (which may or may not be exposed by Xojo) has those events

  • applicationWillResignActive
  • applicationWillTerminate

but as Norman said… it might take special declares to hook into them properly

The Xojo docs suggest that views have a ‘ViewWillDisappear’ event
But I can’t add it in my project, and there is no actual page for it in the docs.


App has no events at all (???)

Search the forum for ImprovediOSApllication. It’s a class I wrote that exposes that event.

Looks good Jason…
I’ll give that a try, thank you!

[quote]Jason King 31 Jan 2015 Pre-Release Testers
I was going to add some of the delegate methods that deal with notifications but that is going to take additional work in creating a few separate classes so I’m actually going to leave it for a later time.
Here is the project:
To use simply add the class to your project and change the super of the App object in your project from iOSApplication to ImprovedIOSApplication. Then implement the events you want and that’s it.

Nope… the old code wont run under Xojo 2018
NSArray constructor failsin

for i as integer = 0 to uboundObject m.UInt32Value(i*SizeOfPointer) = UInt32(objects(i).id) next

with a message “Expected UINT32 but got Ptr”
I cant tell which bit it is complaining about

Delete the modules folder and use the most recent one from iOSKit. That should solve the problem.