Add the event-handler skeleton manually
The application-delegate object
UIApplicationDelegate
manages the iOS
app life cycle using events. You can decide how to implement the life cycle of events; the steps below provide an example that is based loosely on the Apple
Breadcrumbs sample app (with differences in declarations and other key areas). Several of the sample apps included in the SDK also demonstrate the event handling lifecycle.- Specify the entitlement ID (GDApplicationID) and entitlement version (GDApplicationVersion) in theInfo.plistfile. See Using an entitlement ID and version to uniquely identify a BlackBerry Dynamics app.
- ImportGDiOS.hand implement a skeletonGDiOSDelegateprotocol. The following examples forObjective-CandSwiftrely on a boolean variable namedstarted. An alternative approach is to declare the variable in your project's.mfile.:Objective-C// AppDelegate.h #import <UIKit/UIKit.h> #import <GD/GDiOS.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, GDiOSDelegate> { BOOL started; } @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) GDiOS *good; - (void)onAuthorized:(GDAppEvent *)anEvent; - (void)onNotAuthorized:(GDAppEvent *)anEvent; @end:Swiftclass AppDelegate : UIResponder , UIApplicationDelegate, GDiOSDelegate { var window: UIWindow? var good: GDiOS? var started: Bool = false }
- UseGDAppEventto process events. Move the application launch code fromdidFinishLaunchingWithOptionsto theGDAppEventhandler method.:Objective-C// AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.good = [GDiOS sharedInstance]; _good.delegate = self; started = NO; //Show the BlackBerry Authentication UI. [_good authorize]; return YES; } #pragma mark BlackBerry Dynamics Delegate Method - (void)handleEvent:(GDAppEvent *)anEvent { /* Called from _good when events occur, such as system startup. */ switch (anEvent.type) { case GDAppEventAuthorized: { [self onAuthorized:anEvent]; break; } case GDAppEventNotAuthorized: { [self onNotAuthorized:anEvent]; break; } case GDAppEventRemoteSettingsUpdate: { // handle app config changes break; } case GDAppEventPolicyUpdate: { // handle app policy changes break; } case GDAppEventServicesUpdate: { // handle services changes break; } case GDAppEventEntitlementsUpdate: { // handle entitlements changes break ; } default: NSLog(@"Unhandled Event"); break; } }:Swiftfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { //Call BlackBerry Dynamics to authorise the app self.good = GDiOS.sharedInstance() self.good!.delegate = self self.started = false // Show the Good Authentication UI. self.good!.authorize() return true } func handle(_ anEvent: GDAppEvent) { switch anEvent.type { case .authorized: onAuthorized(anEvent: anEvent) break case .notAuthorized: self.onNotAuthorized(anEvent: anEvent) break case .remoteSettingsUpdate: if started { let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) let newViewController = storyBoard.instantiateViewController(withIdentifier: "ShareViewController") as! ShareViewController self.window?.rootViewController = newViewController newViewController.refreshUI() } break case .servicesUpdate: //A change to services-related configuration. break case .policyUpdate: if started { NotificationCenter.default.post(name: NSNotification.Name(rawValue: "AppPolicyUpdated"), object: nil); } break default: print("handleEvent \(anEvent.message)") } }
- Special-case theonNotAuthorizedevents. Verify that the app can handle authorization errors or functionality like remote wipe, a lockout, or blocking events. Implement these events in theonNotAuthorizedfunction.:Objective-C- (void)onNotAuthorized:(GDAppEvent *)anEvent { /* Handle the BlackBerry Libraries not authorized event. */ switch (anEvent.code) { case GDErrorActivationFailed: case GDErrorProvisioningFailed: case GDErrorPushConnectionTimeout: case GDErrorSecurityError: case GDErrorAppDenied: case GDErrorBlocked: case GDErrorWiped: case GDErrorRemoteLockout: case GDErrorPasswordChangeRequired: { // A condition has occurred denying authorization, an application may wish to log these events NSLog(@"onNotAuthorized %@", anEvent.message); break; } case GDErrorIdleLockout: { // idle lockout is benign & informational break; } default: NSAssert(false, @"Unhandled not authorized event"); break; } }:Swiftfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func onNotAuthorized(anEvent:GDAppEvent ) { /* Handle the Good Libraries not authorized event. */ switch anEvent.code { case .errorActivationFailed: break case .errorProvisioningFailed: break case .errorPushConnectionTimeout: break case .errorSecurityError: break case .errorAppDenied: break case .errorAppVersionNotEntitled: break case .errorBlocked: break case .errorWiped: break case .errorRemoteLockout: break case .errorPasswordChangeRequired: // an condition has occured denying authorization, an application may wish to log these events print("onNotAuthorized \(anEvent.message)") case .errorIdleLockout: // idle lockout is benign & informational break default: assert(false, "Unhandled not authorized event"); } }
- On authorization, start the app. Initialize and start the UI with theonAuthorizedfunction. TheGDErrorNoneevent is returned by theBlackBerry Dynamics Runtimewhenever a container is opened and no error occurs.:Objective-C- (void)onAuthorized:(GDAppEvent *)anEvent { /* Handle the BlackBerry Libraries authorized event. */ switch (anEvent.code) { case GDErrorNone: { // started was declared in first step. if (!started) { // launch application UI here started = YES; } break; } default: NSAssert(false, @"Authorized startup with an error"); break; } }:Swiftfunc onAuthorized(anEvent:GDAppEvent ) { /* Handle the Good Libraries authorized event. */ switch anEvent.code { case .errorNone: if !self.started { //Show the User UI self.started = true UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "tabBarController") } default: assert(false, "Authorized startup with an error") break } }