LebianBridge.mm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // LebianBridge.mm
  3. //
  4. // Created by version on 2021/1/29.
  5. // Copyright © 2021 wenting. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <LBSDK/LBInit.h>
  9. #import "Unity/UnityInterface.h"
  10. @interface LebianBridge : NSObject
  11. + (instancetype)sharedInstance;
  12. @property (nonatomic, assign) NSString *callbackGoName;
  13. @end
  14. @implementation LebianBridge
  15. + (instancetype)sharedInstance {
  16. static LebianBridge *uiInit = nil;
  17. static dispatch_once_t onceToken;
  18. dispatch_once(&onceToken, ^{
  19. uiInit = [[LebianBridge alloc] init];
  20. });
  21. return uiInit;
  22. }
  23. - (instancetype)init
  24. {
  25. self = [super init];
  26. return self;
  27. }
  28. - (void)dealloc
  29. {
  30. self.callbackGoName = nil;
  31. }
  32. - (void)SetCallbackGoName:(NSString *) callbackGoName {
  33. self.callbackGoName = callbackGoName;
  34. }
  35. - (BOOL)QueryUpdate {
  36. [LBInit queryUpdate:^(int tag) {
  37. [self CallBackUnity:@"QueryUpdateCallBack" msgData:[NSString stringWithFormat:@"%d", tag]];
  38. }];
  39. return YES;
  40. }
  41. - (BOOL)AfterUpdate {
  42. return [LBInit isDownloadFinished];
  43. }
  44. - (NSString*)GetClientChId {
  45. id childChId = [[NSBundle mainBundle].infoDictionary objectForKey:@"LEBIAN_META"];
  46. if (childChId != NULL && [childChId isKindOfClass:[NSString class]]) {
  47. return (NSString *)childChId;
  48. }
  49. return @"";
  50. }
  51. - (int)GetResVerCode {
  52. return [LBInit getCurrentLBVercode];
  53. }
  54. - (BOOL)IsNullString:(NSString *)string {
  55. if (string == nil || string == NULL) {
  56. return YES;
  57. }
  58. if ([string isKindOfClass:[NSNull class]]) {
  59. return YES;
  60. }
  61. if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
  62. return YES;
  63. }
  64. return NO;
  65. }
  66. - (void)CallBackUnity:(NSString*) methodName msgData:(NSString*) msgData {
  67. if ([self IsNullString:self.callbackGoName]) {
  68. return;
  69. }
  70. if ([self IsNullString:methodName]) {
  71. return;
  72. }
  73. UnitySendMessage([self.callbackGoName UTF8String], [methodName UTF8String], [msgData UTF8String]);
  74. }
  75. @end
  76. extern "C" void LebianBridge_SetCallbackGoName(const char* callbackGoName)
  77. {
  78. [[LebianBridge sharedInstance] setCallbackGoName:[NSString stringWithUTF8String:callbackGoName]];
  79. }
  80. extern "C" bool LebianBridge_QueryUpdate()
  81. {
  82. return [[LebianBridge sharedInstance] QueryUpdate];
  83. }
  84. extern "C" bool LebianBridge_AfterUpdate()
  85. {
  86. return [[LebianBridge sharedInstance] AfterUpdate];
  87. }
  88. extern "C" const char* LebianBridge_GetClientChId()
  89. {
  90. NSString *clientChId = [[LebianBridge sharedInstance] GetClientChId];
  91. return AllocCString(clientChId);
  92. }
  93. extern "C" int LebianBridge_GetResVerCode()
  94. {
  95. return [[LebianBridge sharedInstance] GetResVerCode];
  96. }