- (void)applicationWillTerminate:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName: @"ApplicationWillTerminate" object: self]; }
The NSNotificationCenter logic will send ApplicationWillTerminate to any interested parties. Then in Smalltalk we do:
etupApplicationWillTerminateHandler | defaultCenter selectorString nameString | selectorString := 'applicationWillTerminate:'. nameString := 'ApplicationWillTerminate' asNSStringUTF8. self squeakProxy addSigViaString: selectorString aSignature: 'v@:@'. ObjectiveCBridge performSelectorOnMainThread: [defaultCenter := (ObjectiveCBridge classObjectForName: #NSNotificationCenter) defaultCenter. defaultCenter addObserver: squeakProxy squeakProxy selector: (ObjectiveCBridge findSelectorCalled: selectorString) name: nameString object: 0]. nameString release.
Then on the Proxy we handle the notifiication, in this case since we aren't doing UIKit work we can do the task directly
applicationWillTerminate: aNotification self ui applicationWillTerminate: aNotification applicationWillTerminate: aNotification ObjectiveCBridge wrapWithAutoReleasePool: [self saveWebViewURL]. saveWebViewURL | defaults key possibleRequest url host | defaults := (ObjectiveCBridge classObjectForName: #NSUserDefaults) standardUserDefaults. key := 'WikiServerLastURLUsed' asNSStringUTF8. possibleRequest := self webView request. possibleRequest isNil ifTrue: [^self]. defaults setObject: possibleRequest URL path forKey: key. defaults synchronize. key release.
This code also contains an example of updating the NSUserDefaults standardUserDefaults key value pair WikiServerLastURLUsed which is user data stored
in the application's storage area, so at startup time we can do
getSavedURL | defaults key possibleURL | defaults := (ObjectiveCBridge classObjectForName: #NSUserDefaults) standardUserDefaults. key := 'WikiServerLastURLUsed' asNSStringUTF8. possibleURL := defaults stringForKey: key. key release. ^possibleURL