iOS 中的黑莓集成

Black-Berry Integration in iOS

在 iOS(React-Native) 中集成 Black-Berry 后,当应用程序在模拟器上启动时,它崩溃了。 错误是:-

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].

参考使用:- https://github.com/blackberry/BlackBerry-Dynamics-React-Native-SDK/blob/master/modules/BlackBerry-Dynamics-for-React-Native-Base/README.md

错误截图:-

Main.m class :-

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

您是在尝试 运行 示例应用程序还是在现有项目中集成 Dynamics sdk?

我会推荐 运行 存储库中提供的示例应用程序之一。

此外,当 Dynamics SDK 未正确链接到项目时会发生此错误。尝试删除基本模块并重新添加它。

卡了几天后,我就这样解决了。 所以发布答案希望这可能对某人有所帮助。

在项目中添加objCBBGDiOSDelegate.h文件

@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

和objCBBGDiOSDelegate.m项目中的文件

#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

并且在 appdelegate.m 文件中

#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__);
                            
}

在appDelegate.h添加didAuthorised

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

@property (nonatomic, strong) UIWindow *window;

// GD methods
- (void)didAuthorize;
@end