Goal: The SUP101Appdelegate.h and SUP101Appdelegate.m files are created when you create the Xcode project, but you must add the view controller property and create the view controller instance.
The delegate file extends the functionality of reusable objects. A delegate allows one object to send messages to another object specified as its delegate to ask for input, or to be notified when an event occurs.
@interface SUP101AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navController; - (void)showNoTransportAlert:(NSInteger) ret; @end
#import "SUP101AppDelegate.h" #import "SUPMessageClient.h" #import "SUP101_SUP101DB.h" #import "SUP101CallbackHandler.h" @implementation SUP101AppDelegate @synthesize window; @synthesize navController; - (void)showNoTransportAlert:(NSInteger) ret { NSString *message = nil; if (ret == kSUPMessageClientNoSettings) { message = [[NSString alloc] initWithString:@"No required settings, use the Settings app to enter the provisioning information."]; } else if (ret == kSUPMessageClientKeyNotAvailable) { message = [[NSString alloc] initWithString:@"Unable to access the key."]; } else { message = [[NSString alloc] initWithString:@"Operation fails."]; } UIAlertView * noTransportAlert = [[[UIAlertView alloc] initWithTitle:@"Messaging Client Fails to Start" message:message delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"Label for alert button OK") otherButtonTitles:nil] autorelease]; [noTransportAlert show]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch if([SUP101_SUP101DB databaseExists]) [SUP101_SUP101DB deleteDatabase]; [SUP101_SUP101DB createDatabase]; [MBOLogger setLogLevel:LOG_INFO]; SUP101CallbackHandler* databaseCH = [SUP101CallbackHandler newInstance]; [SUP101_SUP101DB registerCallbackHandler:databaseCH]; [SUP101_SUP101DB createDatabase]; [SUP101_SUP101DB startBackgroundSynchronization]; [NSThread sleepForTimeInterval:2]; NSInteger result = [SUPMessageClient start]; if (result == kSUPMessageClientSuccess) { [SUP101_SUP101DB asyncOnlineLogin:@"supuser" password:@"s3pUser"]; while([databaseCH loginSuccessCount] < 1) { [NSThread sleepForTimeInterval:1]; } [window addSubview:navController.view]; [window makeKeyAndVisible]; } else { [self showNoTransportAlert:result]; } } - (void)applicationWillTerminate:(UIApplication *)application { [SUP101_SUP101DB unsubscribe]; [SUPMessageClient stop]; } - (void)dealloc { [navController release]; [window release]; [super dealloc]; } - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //button index 0 is the cancel button if (buttonIndex == 0){ exit (0); } } @end