| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // LebianBridge.mm
- //
- // Created by version on 2021/1/29.
- // Copyright © 2021 wenting. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- #import <LBSDK/LBInit.h>
- #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];
- }
|