// // LebianBridge.mm // // Created by version on 2021/1/29. // Copyright © 2021 wenting. All rights reserved. // #import #import #import "Unity/UnityInterface.h" @interface LebianBridge : NSObject + (instancetype)sharedInstance; @property (nonatomic, assign) NSString *callbackGoName; @end @implementation LebianBridge + (instancetype)sharedInstance { static LebianBridge *uiInit = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ uiInit = [[LebianBridge alloc] init]; }); return uiInit; } - (instancetype)init { self = [super init]; return self; } - (void)dealloc { self.callbackGoName = nil; } - (void)SetCallbackGoName:(NSString *) callbackGoName { self.callbackGoName = callbackGoName; } - (BOOL)QueryUpdate { [LBInit queryUpdate:^(int tag) { [self CallBackUnity:@"QueryUpdateCallBack" msgData:[NSString stringWithFormat:@"%d", tag]]; }]; return YES; } - (BOOL)AfterUpdate { return [LBInit isDownloadFinished]; } - (NSString*)GetClientChId { id childChId = [[NSBundle mainBundle].infoDictionary objectForKey:@"LEBIAN_META"]; if (childChId != NULL && [childChId isKindOfClass:[NSString class]]) { return (NSString *)childChId; } return @""; } - (int)GetResVerCode { return [LBInit getCurrentLBVercode]; } - (BOOL)IsNullString:(NSString *)string { if (string == nil || string == NULL) { return YES; } if ([string isKindOfClass:[NSNull class]]) { return YES; } if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) { return YES; } return NO; } - (void)CallBackUnity:(NSString*) methodName msgData:(NSString*) msgData { if ([self IsNullString:self.callbackGoName]) { return; } if ([self IsNullString:methodName]) { return; } UnitySendMessage([self.callbackGoName UTF8String], [methodName UTF8String], [msgData UTF8String]); } @end extern "C" void LebianBridge_SetCallbackGoName(const char* callbackGoName) { [[LebianBridge sharedInstance] setCallbackGoName:[NSString stringWithUTF8String:callbackGoName]]; } extern "C" bool LebianBridge_QueryUpdate() { return [[LebianBridge sharedInstance] QueryUpdate]; } extern "C" bool LebianBridge_AfterUpdate() { return [[LebianBridge sharedInstance] AfterUpdate]; } extern "C" const char* LebianBridge_GetClientChId() { NSString *clientChId = [[LebianBridge sharedInstance] GetClientChId]; return AllocCString(clientChId); } extern "C" int LebianBridge_GetResVerCode() { return [[LebianBridge sharedInstance] GetResVerCode]; }