Add the BlackBerry Dynamics SDK event-handler skeleton using notifications in Objective-C
BlackBerry Dynamics SDK
event-handler skeleton using notifications in Objective-C- Specify the entitlement ID (also known as the app ID and version).
- Use theGDStateproperty ofGDiOSto handle the state of theBlackBerry Dynamics Runtime.
- Special-case theonNotAuthorizedevents.
- On authorization, relying on theGDErrorNoneevent, 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.- Specify the entitlement ID and version. Add the following key value pairs to the application'sInfo.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 standaloneGood ControlorBlackBerry UEM.
- Add theBlackBerryDynamicsdictionary with key'CheckEventReceiver'and its Boolean value set toNO.<plist version="1.0"> <dict> ... <key>BlackBerryDynamics</key> <dict> <key>CheckEventReceiver</key> <false/> </dict> ... </dict> </plist>
- ImportGDiOS.handGDState.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
- Build the application and ensure there are no warnings due to partial implementation or errors.
- Make yourAppDelegatean 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); } } }
- UseGDStateto handle the state of theBlackBerry 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; } }
- Enable FIPS Linking (see Link for FIPS in Objective-C or C++).
- Include theGDAssets.bundlein the build phase (see GDAssets.bundle required in build phase ).