iSqueak Wikki : NotificationCenter

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Revision [368]

Most recent edit made on 2009-09-09 12:11:37 by JohnMcIntosh

Additions:
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 |
possibleURL := defaults stringForKey: key.
^possibleURL




Revision [367]

The oldest known version of this page was edited on 2009-09-09 12:08:54 by JohnMcIntosh
On our Objective-C delegate we override the default applicationWillTerminate: and have it broadcast the change to everyone.

- (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.

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.0402 seconds