问题描述
在 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].
错误截图:-
Main.m 类:-
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
解决方法
卡住了几天后,我就这样解决了。 所以发布答案希望这可以帮助某人。
在项目中添加objCBGBDiOSDelegate.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
和项目中的objCBGBDiOSDelegate.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
,
您是尝试运行示例应用程序还是尝试将 Dynamics sdk 集成到现有项目中?
我建议运行存储库中提供的示例应用程序之一。
此外,当 Dynamics SDK 未与项目正确链接时,会发生此错误。尝试移除基础模块并重新添加。