Skip Navigation

Add the 
BlackBerry Dynamics SDK
 event-handler skeleton using notifications in Objective-C

  • Specify the entitlement ID (also known as the app ID and version).
  • Use the 
    GDState
     property of 
    GDiOS
     to handle the state of the 
    BlackBerry Dynamics Runtime
    .
  • Special-case the 
    onNotAuthorized
     events.
  • On authorization, relying on the 
    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. Add the 
    BlackBerryDynamics
     dictionary with key 
    'CheckEventReceiver'
     and its Boolean value set to 
    NO
    .
    <plist version="1.0"> <dict> ... <key>BlackBerryDynamics</key> <dict> <key>CheckEventReceiver</key> <false/> </dict> ... </dict> </plist>
  3. Import 
    GDiOS.h
     and 
    GDState.h
    . The example here relies on a boolean variable named 
    'hasAuthorized'
    . An alternative approach is to declare the variable in your project's .m file.
    // AppDelegate.h #import <UIKit/UIKit.h> #import <GD/GDiOS.h> #import <GD/GDState.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> { BOOL hasAuthorized; } @property (strong, nonatomic) UIWindow *window; - (void)handleStateChange:(GDState *)state; - (void)onAuthorized; - (void)onNotAuthorized:(GDAppResultCode)code; @end
  4. Build the application and ensure there are no warnings due to partial implementation or errors.
  5. Make your 
    AppDelegate
     an observer for state changing notifications.
    // AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [self addStateObserverUsingNotificationCenter]; hasAuthorized = NO; [[GDiOS sharedInstance] authorize]; return YES; } #pragma mark - BlackBerry Dynamics observer for state changes (Notification Center) - (void)addStateObserverUsingNotificationCenter { // register to receive notification center notifications for GD state changes [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveStateChangeNotification:) name:GDStateChangeNotification object:nil]; } - (void) receiveStateChangeNotification:(NSNotification *) notification { if ([[notification name] isEqualToString:GDStateChangeNotification]) { NSDictionary* userInfo = [notification userInfo]; NSString *propertyName = [userInfo objectForKey:GDStateChangeKeyProperty]; GDState* state = [userInfo objectForKey:GDStateChangeKeyCopy]; // For the purposes of this example, we want to log a different message so that it is known // these calls are coming from Notification Center if ([propertyName isEqualToString:GDKeyIsAuthorized]) { NSLog(@"receiveStateChangeNotification - isAuthorized: %@", state.isAuthorized ? @"true" : @"false"); [self handleStateChange:state]; } else if ([propertyName isEqualToString:GDKeyReasonNotAuthorized]) { NSLog(@"receiveStateChangeNotification - reasonNotAuthorized: %ld", (long) state.reasonNotAuthorized); } else if ([propertyName isEqualToString:GDKeyUserInterfaceState]) { NSLog(@"receiveStateChangeNotification - userInterfaceState: %ld", (long) state.userInterfaceState); } else if ([propertyName isEqualToString:GDKeyCurrentScreen]) { NSLog(@"receiveStateChangeNotification - currentScreen: %ld", (long) state.currentScreen); } } }
  6. Use 
    GDState
     to handle the state of the 
    BlackBerry Dynamics Runtime
    .
    // AppDelegate.m #pragma mark - Good Dynamics handler methods for state changes - (void)handleStateChange:(GDState *)state { if (state.isAuthorized) { NSLog(@"gdState: authorized"); [self onAuthorized]; } else { GDAppResultCode errorCode = [state reasonNotAuthorized]; NSLog(@"gdState: not authorized, error:%ld", (long) errorCode); [self onNotAuthorized:errorCode]; } } - (void)onAuthorized { if (!hasAuthorized) { // launch application UI here hasAuthorized = YES; } } - (void)onNotAuthorized:(GDAppResultCode)code { /* Handle the Good Libraries not authorized event. */ switch (code) { case GDErrorActivationFailed: case GDErrorProvisioningFailed: case GDErrorPushConnectionTimeout: case GDErrorSecurityError: case GDErrorAppDenied: case GDErrorAppVersionNotEntitled: case GDErrorBlocked: case GDErrorWiped: case GDErrorRemoteLockout: case GDErrorPasswordChangeRequired: { // an condition has occured denying authorization, an application may wish to log these events NSLog(@"gdState: not authorized, error:%ld", (long) code); break; } case GDErrorIdleLockout: { // idle lockout is benign & informational break; } default: NSAssert(false, @"Unhandled not authorized event"); 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 ).