Skip Navigation

Manually add the 
BlackBerry Dynamics SDK
 event-handler skeleton in Objective-C

You do not need to manually add the code described here if you use the supplied project template. The project template includes all this code automatically. See Create an Objective-C or Swift project with the Xcode template.
The application-delegate object 
UIApplicationDelegate
 manages the 
iOS
 app life cycle using events. 
Many of the sample apps that are installed with the 
BlackBerry Dynamics SDK
 implement the event handling lifecycle. There are several key parts to implementing the life cycle of events. You can decide how to approach the life cycle of events. The following is one example.
  • Specify the entitlement ID (also known as the app ID and version).
  • Use 
    GDAppEvent
     to process events.
  • Special-case the 
    onNotAuthorized
     events. 
  • On authorization, relying on 
    GDErrorNone
     event, start the app UI. 
This example is based loosely on 
Apple
's Breadcrumbs sample app. However, there are significant differences in declarations and elsewhere. The important point is the event handling, not the overall purpose of the app.
  1. Specify the entitlement ID and version. Add the following key value pairs to the application's 
    Info.plist
    . For background, see BlackBerry Dynamics entitlement ID and version and Required build-time declarations: URL type.
    The values must correspond to the entitlement ID and version defined in standalone 
    Good Control
     or 
    BlackBerry UEM
    .
  2. Import 
    GDiOS.h
     and implement a skeleton 
    GDiOSDelegate
     protocol. The example here relies on a boolean variable named 
    started
    . An alternative approach is to declare the variable in your project's .m file.
    // 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
  3. Build the application and ensure there are no warnings due to partial implementation or errors.
  4. Use 
    GDAppEvent
     to process events. Move the application launch code from 
    didFinishLaunchingWithOptions
     to 
    GDAppEvent
     handler method.
    // 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; } }
  5. Special-case the 
    onNotAuthorized
     events. Make sure the application can handle problems such as authorization errors or functionality like remote wipe, a lockout, or blocking events. Implement these events in the 
    onNotAuthorized
     function.
    - (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; } }
  6.  On authorization, start the application. Initialize and start the application UI with the 
    onAuthorized
     function. The 
    GDErrorNone
     event is returned by the 
    BlackBerry Dynamics Runtime
     whenever a container is opened and no error has been encountered; you could test for it as an alternative to the boolean 
    started
     shown here.
    - (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; } }
  7. Enable FIPS linking. See Link for FIPS in Objective-C or C++.
  8. Include the 
    GDAssets.bundle
     in the build phase. See GDAssets.bundle required in build phase.