0

After integration of Black-Berry in iOS(React-Native), when app launches on simulator, it got crashed. Error is :-

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Delegate property not set. Either call [GDiOS authorize:] and pass an object that
implements the GDiOSDelegate protocol, or set the delegate property of the GDiOS instance prior
to calling [GDiOS authorize].

Reference used :- https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/blob/master/modules/BlackBerry-Dynamics-for-React-Native-Base/README.md

Error Screenshot:-

enter image description here

Main.m class :-

enter image description here

AppDelegate.h :-

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <BlackBerryDynamics/GD/GDiOS.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate,GDiOSDelegate>

@property (nonatomic, strong) UIWindow *window;

@end
piyush ranjan
  • 391
  • 4
  • 15

2 Answers2

1

After stuck few days I solved it like this. So posting the answers hoping this may helps someone.

Add objCBBGDiOSDelegate.h file in the project

@import GD.Runtime;
#import "AppDelegate.h"

@interface objCBBGDiOSDelegate : NSObject <GDiOSDelegate>

@property (weak, nonatomic) UIViewController *rootViewController;
@property (weak, nonatomic) AppDelegate *appDelegate;
@property (assign,nonatomic,readonly) BOOL hasAuthorized;
                            
+(instancetype)sharedInstance;
                        
@end

and objCBBGDiOSDelegate.m file in the project

#import "objCBBGDiOSDelegate.h"

@interface objCBBGDiOSDelegate ()


@property (nonatomic, assign) BOOL hasAuthorized;                           
                        

-(instancetype)init;
-(void)didAuthorize;                        
                        
@end

@implementation objCBBGDiOSDelegate

+ (instancetype)sharedInstance {

    static objCBBGDiOSDelegate *gdiOSDelegate = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        gdiOSDelegate = [[objCBBGDiOSDelegate alloc] init];
    });
    return gdiOSDelegate;                           
                            
}


- (instancetype)init {
    self = [super init];
    if (self) {

        // Do any additional setup                      
                                
    }
    return self;
}

- (void)setRootViewController {

    [self didAuthorize];                            
                            
}


- (void)setAppDelegate:(AppDelegate *)appDelegate {

    _appDelegate = appDelegate;
    [self didAuthorize];                            
                            
}


- (void)didAuthorize {

        [self.appDelegate didAuthorize];
                            
}



#pragma mark - BlackBerry Dynamics SDK Delegate Methods
- (void)handleEvent:(GDAppEvent *)anEvent {

    /* Called from BlackBerry Dynamics SDK when events occur, such as system startup. */
    switch (anEvent.type)
    {
        case GDAppEventAuthorized:
        {
            [self onAuthorized:anEvent];
            break;
        }
        case GDAppEventNotAuthorized:
        {
            [self onNotAuthorized:anEvent];
            break;
        }
        case GDAppEventRemoteSettingsUpdate:
        {
            //A change to application-related configuration or policy settings.
            break;
        }
        case GDAppEventServicesUpdate:
        {
            //A change to services-related configuration.
            break;
        }
        case GDAppEventPolicyUpdate:
        {
            //A change to one or more application-specific policy settings has been received.
            break;
        }
        case GDAppEventEntitlementsUpdate:
        {
            //A change to the entitlements data has been received.
            break;
        }
        default:
        {
            NSLog(@"Unhandled Event");
            break;
        }
    }
}

- (void)onNotAuthorized:(GDAppEvent *)anEvent {

    /* Handle the BlackBerry Dynamics SDK not authorized event. */
    switch (anEvent.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(@"onNotAuthorized %@", anEvent.message);
            break;
        }
        case GDErrorIdleLockout: {
            // idle lockout is benign & informational
            break;
        }
        default: 
            NSAssert(false, @"Unhandled not authorized event");
            break;
    }
}


- (void)onAuthorized:(GDAppEvent *)anEvent {

    /* Handle the BlackBerry Dynamics SDK authorized event. */                            
    switch (anEvent.code) {
        case GDErrorNone: {
            if (!self.hasAuthorized) {
 
        
                self.hasAuthorized = YES;
        
                [self didAuthorize];
        
            }
            break;
        }
        default:
            NSAssert(false, @"Authorized startup with an error");
            break;
    }
}


@end

And in the appdelegate.m file

#import "objCBBGDiOSDelegate.h"
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
  
  [objCBBGDiOSDelegate sharedInstance].appDelegate = self;
  [[GDiOS sharedInstance] authorize:[objCBBGDiOSDelegate sharedInstance]];
  return YES;
}

- (void)didAuthorize {

    NSLog(@"%s", __FUNCTION__);
                            
}

In the appDelegate.h add didAuthorised

@import GD.Runtime;
extern UIViewController *rootViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>

@property (nonatomic, strong) UIWindow *window;

// GD methods
- (void)didAuthorize;
@end
piyush ranjan
  • 391
  • 4
  • 15
0

Are you trying to run a sample application or trying to integrate Dynamics sdk in an existing project?

I would recommend running one of the sample application provided in the repo.

Also, this error happens when Dynamics SDK is not linked correctly with the project. Try to remove the base module and re-adding it.

GGhangura
  • 31
  • 4