|
@@ -7,8 +7,11 @@
|
|
|
|
|
|
|
|
|
|
#import "IOSPlatformSDK.h"
|
|
#import "IOSPlatformSDK.h"
|
|
|
|
+//#import "AvoidCrash.h"
|
|
|
|
+//#import <Bugly/Bugly.h>
|
|
|
|
|
|
-#pragma mark ============================>> ios call unity C语言指针声明 start
|
|
|
|
|
|
+#pragma mark ============================>> ios call unity (定义名字参数和C#类一样的方法)
|
|
|
|
+//大概流程就是先将C#的函数指针存入OC内存,在OC需要回调unity的时候就可以使用不同的指针来回调不同的unity方法
|
|
/**
|
|
/**
|
|
*运动数据
|
|
*运动数据
|
|
* left: 左鞋动作代码
|
|
* left: 左鞋动作代码
|
|
@@ -61,26 +64,22 @@ typedef void (* ActionHandler) (int cusid, int code);
|
|
*/
|
|
*/
|
|
typedef void (* GetRankHandler)(int conde,const char * userJson);
|
|
typedef void (* GetRankHandler)(int conde,const char * userJson);
|
|
|
|
|
|
-ActionHandler actionHandler;
|
|
|
|
-MotionHandler motionHandler;
|
|
|
|
-StepHandler stepHandler;
|
|
|
|
-DeviceHandler deviceHandler;
|
|
|
|
-UserFriendsHandler userFriendsHandler;
|
|
|
|
-InviteFriendHandler inviteFriendHandler;
|
|
|
|
-GetRankHandler getRankHandler;
|
|
|
|
-
|
|
|
|
-//
|
|
|
|
-#pragma mark ============================>> ios call unity C语言指针声明 结束
|
|
|
|
-
|
|
|
|
-@interface IOSPlatformSDK ()
|
|
|
|
-
|
|
|
|
-//计算游戏启动时间
|
|
|
|
-@property(nonatomic,strong)NSDate * firstTime;
|
|
|
|
-
|
|
|
|
-@property(nonatomic,strong)UILabel * testLabel;
|
|
|
|
-@property(copy,nonatomic)NSString * macAddress;
|
|
|
|
-
|
|
|
|
-@end
|
|
|
|
|
|
+/** array: x,y,z姿态数据
|
|
|
|
+* 单位:弧度
|
|
|
|
+* 使用时要将数据 除以 10000
|
|
|
|
+* 转换角度可以使用 Mathf.Rad2Deg
|
|
|
|
+*/
|
|
|
|
+typedef void (* RotateHandler)(int cusid,int right_pos[3],int left_pos[3],int right_att[3],int left_att[3],int righrAcc[3],int leftAcc[3]);
|
|
|
|
+
|
|
|
|
+#pragma mark ============================>> 声明 静态指针变量的实例 在unity call ios时候将该指针存储在内存中,在需要ios call unity时,用该指针调用unity的函数接口
|
|
|
|
+static ActionHandler actionHandler;
|
|
|
|
+static MotionHandler motionHandler;
|
|
|
|
+static StepHandler stepHandler;
|
|
|
|
+static DeviceHandler deviceHandler;
|
|
|
|
+static UserFriendsHandler userFriendsHandler;
|
|
|
|
+static InviteFriendHandler inviteFriendHandler;
|
|
|
|
+static GetRankHandler getRankHandler;
|
|
|
|
+static RotateHandler rotateHandler;
|
|
|
|
|
|
@implementation IOSPlatformSDK
|
|
@implementation IOSPlatformSDK
|
|
|
|
|
|
@@ -102,251 +101,52 @@ static IOSPlatformSDK * instance;
|
|
static dispatch_once_t onceToken;
|
|
static dispatch_once_t onceToken;
|
|
dispatch_once(&onceToken, ^{
|
|
dispatch_once(&onceToken, ^{
|
|
instance = [super init];
|
|
instance = [super init];
|
|
- [self initNotification];
|
|
|
|
-
|
|
|
|
- [Bugly startWithAppId:@"403d275730"];
|
|
|
|
|
|
+ [BTDataProcess sharedInstance];
|
|
|
|
+// [Bugly startWithAppId:@"36a0c05291"];
|
|
//防奔溃
|
|
//防奔溃
|
|
- [AvoidCrash makeAllEffective];
|
|
|
|
- NSArray *noneSelClassStrings = @[
|
|
|
|
- @"NSString"
|
|
|
|
- ];
|
|
|
|
- [AvoidCrash setupNoneSelClassStringsArr:noneSelClassStrings];
|
|
|
|
- NSArray *noneSelClassPrefix = @[
|
|
|
|
- @"AvoidCrash"
|
|
|
|
- ];
|
|
|
|
- [AvoidCrash setupNoneSelClassStringPrefixsArr:noneSelClassPrefix];
|
|
|
|
- //监听通知:AvoidCrashNotification, 获取AvoidCrash捕获的崩溃日志的详细信息
|
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealwithCrashMessage:) name:AvoidCrashNotification object:nil];
|
|
|
|
|
|
+// [AvoidCrash makeAllEffective];
|
|
|
|
+// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealwithCrashMessage:) name:AvoidCrashNotification object:nil];
|
|
});
|
|
});
|
|
return instance;
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)dealwithCrashMessage:(NSNotification *)note{
|
|
|
|
-
|
|
|
|
- NSDictionary *info = note.userInfo;
|
|
|
|
- NSString *errorReason = [NSString stringWithFormat:@"【ErrorReason】%@========【ErrorPlace】%@========【DefaultToDo】%@========【ErrorName】%@", info[@"errorReason"], info[@"errorPlace"], info[@"defaultToDo"], info[@"errorName"]];
|
|
|
|
- NSArray *callStack = info[@"callStackSymbols"];
|
|
|
|
- [self reportErrorName:@"Bugly_ErrorName_AvoidCrash" errorReason:errorReason callStack:callStack extraInfo:nil];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/** 上报错误信息 */
|
|
|
|
-- (void)reportErrorName:(NSString *)errorName errorReason:(NSString *)errorReason callStack:(NSArray *)aStackArray extraInfo:(NSDictionary *)info{
|
|
|
|
-[Bugly reportExceptionWithCategory:3 name:errorName reason:errorReason callStack:aStackArray extraInfo:info terminateApp:NO];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark ============================>> public method app跳转直链
|
|
|
|
--(void)startWithUrl:(NSURL*)url{//
|
|
|
|
-
|
|
|
|
- if (url==nil){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- NSString * urlString = [url absoluteString];
|
|
|
|
- NSArray * stringArr = [urlString componentsSeparatedByString:@"//"];
|
|
|
|
- NSString * arr2 = stringArr[1];
|
|
|
|
- NSString* finsalString = [arr2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- NSDictionary * urlDict = [AlgorithmTool dictionaryWithJsonString:finsalString];
|
|
|
|
- NSLog(@"Schemes_Url转码的dict ========= %@",urlDict);
|
|
|
|
-
|
|
|
|
- //固定一个时间戳
|
|
|
|
- NSString * timestamp = [AlgorithmTool returnTimestamp];
|
|
|
|
- [IOS_NSUSERDEFAULT setObject:timestamp forKey:IOSSDK_TIMESTAMP];
|
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
|
-
|
|
|
|
- if (urlDict!=nil){
|
|
|
|
- //缓存用户信息数据
|
|
|
|
- [IOS_NSUSERDEFAULT setObject:urlDict forKey:IOSSDK_USERINFO];
|
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
|
- //主副设备:deviceType 游戏种类:game_id mac地址:macAddress
|
|
|
|
- BTDataProcess* bleInstance = [BTDataProcess sharedInstance];
|
|
|
|
- bleInstance.deviceType = DEVICETYPE_MAIN;
|
|
|
|
- NSString * game_id = urlDict[@"game_id"];
|
|
|
|
- bleInstance.game_id = (GAME_TYPE)[game_id intValue];
|
|
|
|
- if ([urlDict objectForKey:@"mac"]!=nil){
|
|
|
|
- bleInstance.macAddress = [urlDict objectForKey:@"mac"];
|
|
|
|
- self.macAddress = [urlDict objectForKey:@"mac"];
|
|
|
|
- }
|
|
|
|
- //链接蓝牙
|
|
|
|
- [bleInstance initCBCentralManager];
|
|
|
|
- //数据存入plist
|
|
|
|
- bleInstance.allMotionCountBLock = ^(int jump_count, int crouch_count, int step_count){
|
|
|
|
-// NSLog(@"jump_count = %d crouch_count = %d step_count = %d ",jump_count,crouch_count,step_count);
|
|
|
|
- [self cacheAllMotionCount:jump_count crouchCount:crouch_count stepCount:step_count];
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- //先打开app后已经创建了label,第二次open重新赋值
|
|
|
|
- self.testLabel.text = [NSString stringWithFormat:@"%@ mac: %@",self.openStyle,self.macAddress];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark ============================>> private 各类通知处理事件
|
|
|
|
--(void)initNotification{
|
|
|
|
-
|
|
|
|
- //监听各类通知action
|
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(gameStartInitData) name:@"gameStartInitData" object:nil];
|
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(gameEndInitData:) name:@"gameEndInitData" object:nil];
|
|
|
|
- [CUS_NOTIFICATIONCENTER addObserver:self selector:@selector(searchBLEAction:) name:@"searchBLEAction" object:nil];
|
|
|
|
- //监听 app group 消息 ==>> 好友邀请信息
|
|
|
|
- CFStringRef invite = (__bridge CFStringRef)@"INVITE_NOTIFICATION";
|
|
|
|
- CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
|
|
|
|
- NULL,
|
|
|
|
- inviteFriends,
|
|
|
|
- invite,
|
|
|
|
- NULL,
|
|
|
|
- CFNotificationSuspensionBehaviorDeliverImmediately);
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//趣动app:广播的通知回调
|
|
|
|
-void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
|
|
|
|
-
|
|
|
|
- //group.com.Oujia.AppAndGame 沙河数据
|
|
|
|
- NSUserDefaults* userDefault = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.Oujia.AppAndGame"];
|
|
|
|
- //趣动传过来的 invite json字符串转字典
|
|
|
|
- NSString * string = [userDefault objectForKey:@"invite"];
|
|
|
|
- NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- NSDictionary * inviteDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
- if (inviteDict!=nil){
|
|
|
|
- //字典取值
|
|
|
|
- NSDictionary * invite = [inviteDict objectForKey:@"invite"];
|
|
|
|
- NSDictionary * user = [invite objectForKey:@"user"];
|
|
|
|
- //user字典转字符串
|
|
|
|
- NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
- NSString * userString = [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
|
|
|
|
- const char * userChar =[userString UTF8String];
|
|
|
|
- //info字典转字符串
|
|
|
|
- NSString * infoString = invite[@"info"];
|
|
|
|
- const char * infoChar =[infoString UTF8String];
|
|
|
|
- NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>> %s , %s",userChar,infoChar);
|
|
|
|
- inviteFriendHandler(0,userChar,infoChar);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//通知开始游戏
|
|
|
|
--(void)gameStartInitData{
|
|
|
|
- NSLog(@"unity call ios 通知开始游戏 --> IOSPlatformSDK");
|
|
|
|
- [[BTDataProcess sharedInstance] gameStartInitData];
|
|
|
|
- if ([self existUserInfo]){
|
|
|
|
- self.firstTime = [NSDate date];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+//- (void)dealwithCrashMessage:(NSNotification *)note{
|
|
|
|
+//
|
|
|
|
+// NSDictionary *info = note.userInfo;
|
|
|
|
+// NSString *errorReason = [NSString stringWithFormat:@"【ErrorReason】%@========【ErrorPlace】%@========【DefaultToDo】%@========【ErrorName】%@", info[@"errorReason"], info[@"errorPlace"], info[@"defaultToDo"], info[@"errorName"]];
|
|
|
|
+// NSLog(@"errorReason = %@",errorReason);
|
|
|
|
+// NSArray *callStack = info[@"callStackSymbols"];
|
|
|
|
+// [self reportErrorName:@"Bugly_ErrorName_AvoidCrash" errorReason:errorReason callStack:callStack extraInfo:nil];
|
|
|
|
+//
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+///** 上报错误信息 */
|
|
|
|
+//- (void)reportErrorName:(NSString *)errorName errorReason:(NSString *)errorReason callStack:(NSArray *)aStackArray extraInfo:(NSDictionary *)info{
|
|
|
|
+// [Bugly reportExceptionWithCategory:3 name:errorName reason:errorReason callStack:aStackArray extraInfo:info terminateApp:NO];
|
|
|
|
+//}
|
|
|
|
|
|
-//通知结束游戏
|
|
|
|
--(void)gameEndInitData:(NSNotification*)notification{
|
|
|
|
- [[BTDataProcess sharedInstance] gameEndInitData];
|
|
|
|
- NSLog(@"unity call ios 通知结束游戏 --> IOSPlatformSDK");
|
|
|
|
|
|
+#pragma mark ============================>> public method app 跳转直链
|
|
|
|
+-(void)startWithUrl:(NSURL*)url{
|
|
|
|
+ [BTDataInstance startWithUrl:url];
|
|
}
|
|
}
|
|
|
|
|
|
-//通知弹出蓝牙搜索框
|
|
|
|
--(void)searchBLEAction:(NSNotification*)notification{
|
|
|
|
-
|
|
|
|
- NSLog(@"unity call ios 通知游戏弹窗 --> IOSPlatformSDK");
|
|
|
|
- if ([instance existUserInfo]==NO){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- /***************************初始化蓝牙数据处理工具***************************/
|
|
|
|
- //主副设备:deviceType 游戏种类:game_id mac地址:macAddress
|
|
|
|
- BTDataProcess* bleInstance = [BTDataProcess sharedInstance];
|
|
|
|
- NSDictionary * notificationDict = notification.userInfo;
|
|
|
|
- NSNumber * typeNumber = [notificationDict objectForKey:@"type"];
|
|
|
|
- int type = [typeNumber intValue];
|
|
|
|
- bleInstance.deviceType = (DEVICE_TYPE)type;
|
|
|
|
- NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSString * game_id = jsonDict[@"game_id"];
|
|
|
|
- bleInstance.game_id = (GAME_TYPE)[game_id intValue];
|
|
|
|
- bleInstance.macAddress = @"";
|
|
|
|
- //初始化蓝牙CBCentralManager
|
|
|
|
- [bleInstance initCBCentralManager];
|
|
|
|
- //缓存动作数据
|
|
|
|
- bleInstance.allMotionCountBLock = ^(int jump_count, int crouch_count, int step_count){
|
|
|
|
-// NSLog(@"jump_count = %d crouch_count = %d step_count = %d ",jump_count,crouch_count,step_count);
|
|
|
|
- [self cacheAllMotionCount:jump_count crouchCount:crouch_count stepCount:step_count];
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- /***************************搜索蓝牙外设弹窗***************************/
|
|
|
|
- SearchDeviceViewController * searchVC = [SearchDeviceViewController new];
|
|
|
|
- [self addTOwindow:searchVC];
|
|
|
|
- //searchVC搜索蓝牙Button
|
|
|
|
- searchVC.searchDeviceTask = ^{
|
|
|
|
- [bleInstance initCBCentralManager];
|
|
|
|
- };
|
|
|
|
- //BTDataProces搜索到的蓝牙外设-->searchVC
|
|
|
|
- bleInstance.deviceArrBLock = ^(NSMutableArray * arr){//蓝牙数据回调 刷新popView数据
|
|
|
|
- searchVC.deviceArray = arr;
|
|
|
|
- [searchVC reloadData];
|
|
|
|
-// [searchVC hideAnimation];
|
|
|
|
- };
|
|
|
|
- //点击searchVC的tableViewCell链接选中的蓝牙
|
|
|
|
- searchVC.connectDeviceBlock = ^(CBPeripheral * peripheral){
|
|
|
|
- bleInstance.deviceType = (DEVICE_TYPE)type;
|
|
|
|
-// NSLog(@"connectDeviceBlock = %@ %ld",peripheral,(long)bleInstance.deviceType);
|
|
|
|
- [bleInstance connectPeripheral:peripheral];
|
|
|
|
- bleInstance.macAddress = peripheral.identifier.UUIDString;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- //bleInstance脚步交互动作-->searchVC
|
|
|
|
- bleInstance.getInteractionBlock = ^(int interaction){
|
|
|
|
- if (interaction!=-1){
|
|
|
|
- NSLog(@"BTDataProcess 有效交互动作 ===>> %d",interaction);
|
|
|
|
-// [searchVC getInteraction:interaction];
|
|
|
|
- }else{
|
|
|
|
-// NSLog(@"BTDataProcess 无效交互动作 ===>> %@",@"原地");
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
//
|
|
//
|
|
-#pragma mark ============================>> private 全局弹窗
|
|
|
|
--(void)addTOwindow:(UIViewController*)searchVC{
|
|
|
|
-
|
|
|
|
- UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
|
|
|
|
- UIViewController *parent = rootVC;
|
|
|
|
- while ((parent = rootVC.presentedViewController) != nil ){
|
|
|
|
- rootVC = parent;
|
|
|
|
- }
|
|
|
|
- while ([rootVC isKindOfClass:[UINavigationController class]]){
|
|
|
|
- rootVC = [(UINavigationController *)rootVC topViewController];
|
|
|
|
- }
|
|
|
|
- [rootVC addChildViewController:searchVC];
|
|
|
|
- [rootVC.view addSubview:searchVC.view];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark ============================>> private 缓存处理
|
|
|
|
|
|
+#pragma mark ============================>> private
|
|
//是否已经缓存到用户信息
|
|
//是否已经缓存到用户信息
|
|
-(BOOL)existUserInfo{
|
|
-(BOOL)existUserInfo{
|
|
|
|
|
|
NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
- if (jsonDict==nil){
|
|
|
|
-// [PopupView showCusHUDA:@"获取趣动用户数据失败"];
|
|
|
|
- return YES;
|
|
|
|
|
|
+ if ([jsonDict isKindOfClass:[NSNull class]] || jsonDict == nil || [jsonDict isEqual:[NSNull null]]){
|
|
|
|
+ [PopupView showCusHUDA:@"获取用户信息失败,请从趣动启动"];
|
|
|
|
+ return NO;
|
|
}else{
|
|
}else{
|
|
return YES;
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//玩游戏过程中缓存 动作数据 和时间戳
|
|
|
|
--(void)cacheAllMotionCount:(int)jump_count crouchCount:(int)crouch_count stepCount:(int)step_count{
|
|
|
|
-
|
|
|
|
- //游戏持续时间
|
|
|
|
- NSTimeInterval durationTime = [[NSDate date] timeIntervalSinceDate:self.firstTime];//游戏总共经历的时长 秒数
|
|
|
|
- //缓存pilst文件
|
|
|
|
- NSMutableDictionary * bleDict = [NSMutableDictionary new];
|
|
|
|
- [bleDict setObject:[NSNumber numberWithInt:durationTime] forKey:@"duration"];
|
|
|
|
- [bleDict setObject:[NSNumber numberWithInt:jump_count] forKey:@"jump"];
|
|
|
|
- [bleDict setObject:[NSNumber numberWithInt:crouch_count] forKey:@"crouch"];
|
|
|
|
- [bleDict setObject:[NSNumber numberWithInt:step_count] forKey:@"step"];
|
|
|
|
- NSDictionary * dict = [NSDictionary dictionaryWithDictionary:bleDict];
|
|
|
|
- //归档缓存
|
|
|
|
- [IOS_NSUSERDEFAULT setObject:dict forKey:IOSSDK_BLESDKDATA];
|
|
|
|
- [IOS_NSUSERDEFAULT synchronize];
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#pragma mark ============================>> ios call unity
|
|
|
|
|
|
+//
|
|
|
|
+#pragma mark ============================>> ios call unity (数据处理后的回调)
|
|
-(void)bridgingMotionAction:(int)cusid
|
|
-(void)bridgingMotionAction:(int)cusid
|
|
left:(int)left
|
|
left:(int)left
|
|
right:(int)right{
|
|
right:(int)right{
|
|
@@ -360,8 +160,9 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
rightStatus:(int)rightStatus
|
|
rightStatus:(int)rightStatus
|
|
leftFrag:(int)leftFrag
|
|
leftFrag:(int)leftFrag
|
|
rightFrag:(int)rightFrag{
|
|
rightFrag:(int)rightFrag{
|
|
- // NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
|
|
|
|
- stepHandler(cusid,leftStatus,rightStatus,leftFrag,rightFrag);
|
|
|
|
|
|
+ if (stepHandler != nil){
|
|
|
|
+ stepHandler(cusid,leftStatus,rightStatus,leftFrag,rightFrag);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-(void)bridgingDeviceAction:(int)cusid
|
|
-(void)bridgingDeviceAction:(int)cusid
|
|
@@ -370,24 +171,31 @@ void inviteFriends (CFNotificationCenterRef center, void *observer, CFStringRef
|
|
status:(int)status
|
|
status:(int)status
|
|
electricity:(int)electricity{
|
|
electricity:(int)electricity{
|
|
// NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
|
|
// NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
|
|
- //
|
|
|
|
const char * charName =[name UTF8String];
|
|
const char * charName =[name UTF8String];
|
|
const char * charAddress =[address UTF8String];
|
|
const char * charAddress =[address UTF8String];
|
|
- if (deviceHandler!=nil){
|
|
|
|
|
|
+ if (deviceHandler != nil){
|
|
deviceHandler(cusid,charName,charAddress,status,electricity);
|
|
deviceHandler(cusid,charName,charAddress,status,electricity);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
-(void)bridgingInteraction:(int)cusid
|
|
-(void)bridgingInteraction:(int)cusid
|
|
code:(int)code{
|
|
code:(int)code{
|
|
//传给unity ---> 旧版游戏未用到
|
|
//传给unity ---> 旧版游戏未用到
|
|
-// actionHandler(cusid,code);
|
|
|
|
|
|
+ if (actionHandler != nil){
|
|
|
|
+// actionHandler(cusid,code);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-@end
|
|
|
|
|
|
+-(void)bridgingInvite:(int)code
|
|
|
|
+ userChar:(const char *)userChar
|
|
|
|
+ infoChar:(const char *)infoChar{
|
|
|
|
+ inviteFriendHandler(0,userChar,infoChar);
|
|
|
|
+}
|
|
|
|
|
|
|
|
+@end
|
|
|
|
|
|
-#pragma mark ============================>> unity call ios
|
|
|
|
|
|
+#pragma mark ============================>> unity call ios (声明unity call ios的托管函数 & 接收unity传过来的指针)
|
|
/**
|
|
/**
|
|
* c语言字符串指针malloc
|
|
* c语言字符串指针malloc
|
|
*/
|
|
*/
|
|
@@ -476,16 +284,14 @@ extern "C" {void PointerGetRankHandler(GetRankHandler handler){
|
|
* 游戏开始
|
|
* 游戏开始
|
|
*/
|
|
*/
|
|
void GameStart(){
|
|
void GameStart(){
|
|
-
|
|
|
|
NSLog(@"Unity 请求开始游戏 GameStart ===>>");
|
|
NSLog(@"Unity 请求开始游戏 GameStart ===>>");
|
|
-
|
|
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- [CUS_NOTIFICATIONCENTER postNotificationName:@"gameStartInitData" object:nil];
|
|
|
|
- [HTTPDataProcession gameStart];
|
|
|
|
-
|
|
|
|
|
|
+ //蓝牙
|
|
|
|
+ [BTDataInstance gameStartInitData];
|
|
|
|
+ //http
|
|
|
|
+ [HTTPDataProcession gameStart];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -499,21 +305,17 @@ void GameStart(){
|
|
void GameEnd(int level, double score, int record, int mode, int opponentId){
|
|
void GameEnd(int level, double score, int record, int mode, int opponentId){
|
|
|
|
|
|
NSLog(@"Unity 请求结束游戏 GameEnd ===>> %d %f %d %d %d",level,score,record,mode,opponentId);
|
|
NSLog(@"Unity 请求结束游戏 GameEnd ===>> %d %f %d %d %d",level,score,record,mode,opponentId);
|
|
-
|
|
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- [CUS_NOTIFICATIONCENTER postNotificationName:@"gameEndInitData" object:nil];
|
|
|
|
-
|
|
|
|
|
|
+ [BTDataInstance gameEndInitData];
|
|
|
|
+ //http
|
|
[HTTPDataProcession gameEnd];
|
|
[HTTPDataProcession gameEnd];
|
|
-
|
|
|
|
//上传数据
|
|
//上传数据
|
|
[HTTPDataProcession postGameRecord:level score:score record:record mode:mode opponentId:opponentId gameEndDataBlock:^(NSString *jsonString){
|
|
[HTTPDataProcession postGameRecord:level score:score record:record mode:mode opponentId:opponentId gameEndDataBlock:^(NSString *jsonString){
|
|
NSLog(@"IOS_SKD 回调结束游戏请求 GameEnd ===> %@",jsonString);
|
|
NSLog(@"IOS_SKD 回调结束游戏请求 GameEnd ===> %@",jsonString);
|
|
}];
|
|
}];
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 搜索设备
|
|
* 搜索设备
|
|
@@ -521,10 +323,12 @@ void GameEnd(int level, double score, int record, int mode, int opponentId){
|
|
*/
|
|
*/
|
|
void SearchDevice(int type){
|
|
void SearchDevice(int type){
|
|
//unity 有两个search按钮 type 0是主设备 1是副设备
|
|
//unity 有两个search按钮 type 0是主设备 1是副设备
|
|
- NSDictionary * dict = @{@"type":@(type)};
|
|
|
|
- NSLog(@"Unity 请求搜索设备 SearchDevice ===>> %@",dict);
|
|
|
|
- [CUS_NOTIFICATIONCENTER postNotificationName:@"searchBLEAction" object:nil userInfo:dict];
|
|
|
|
- }
|
|
|
|
|
|
+ NSLog(@"Unity 请求搜索设备 type ===>> %d",type);
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ [BTDataInstance searchBLEAction:type];
|
|
|
|
+}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 链接设备
|
|
* 链接设备
|
|
@@ -532,6 +336,9 @@ void SearchDevice(int type){
|
|
*/
|
|
*/
|
|
void ConnectDevice(int type){
|
|
void ConnectDevice(int type){
|
|
NSLog(@"Unity 请求链接设备 ConnectDevice ===>> %d",type);
|
|
NSLog(@"Unity 请求链接设备 ConnectDevice ===>> %d",type);
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
//unity 有两个connect按钮 type 0是第一个玩家 1是第二个玩家
|
|
//unity 有两个connect按钮 type 0是第一个玩家 1是第二个玩家
|
|
}
|
|
}
|
|
|
|
|
|
@@ -541,31 +348,36 @@ void ConnectDevice(int type){
|
|
* duration: 时长 ms [100 .. 1000]
|
|
* duration: 时长 ms [100 .. 1000]
|
|
*/
|
|
*/
|
|
void Vibrate(int type,int duration){
|
|
void Vibrate(int type,int duration){
|
|
- //unity 有两个search按钮 type 0是主设备 1是副设备
|
|
|
|
- NSMutableDictionary * obj = [NSMutableDictionary new];
|
|
|
|
- [obj setObject:@(type) forKey:@"type"];
|
|
|
|
- [obj setObject:@(duration) forKey:@"duration"];
|
|
|
|
- NSDictionary * dict = [NSDictionary dictionaryWithDictionary:obj];
|
|
|
|
- NSLog(@"vibrate ===>> %@",dict);
|
|
|
|
- [CUS_NOTIFICATIONCENTER postNotificationName:@"vibrationAction" object:nil userInfo:dict];
|
|
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ [BTDataInstance vibrationAction:type duration:duration];
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* 震动
|
|
|
|
+* type: 设备ID
|
|
|
|
+* duration: 时长 ms [100 .. 1000]
|
|
|
|
+*/
|
|
|
|
+void Vibrates(int type,int duration,int leftOrRight){
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ [BTDataInstance vibrationAction:type duration:duration];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* unity获取用户好友列表 -->> ios端根据用户token值请求http好友列表 ios将列表json的数组数据传给unity
|
|
* unity获取用户好友列表 -->> ios端根据用户token值请求http好友列表 ios将列表json的数组数据传给unity
|
|
*/
|
|
*/
|
|
void GetUserFriends(){
|
|
void GetUserFriends(){
|
|
-
|
|
|
|
- NSLog(@"Unity 请求好友列表 GetUserFriends ===>>");
|
|
|
|
-
|
|
|
|
|
|
+// NSLog(@"Unity 请求好友列表 GetUserFriends ===>>");
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
[HTTPDataProcession getFriendsList:^(int code, const char *jsonString){
|
|
[HTTPDataProcession getFriendsList:^(int code, const char *jsonString){
|
|
NSLog(@"IOS_SKD 回调好友列表 GetUserFriends ===> %s",jsonString);
|
|
NSLog(@"IOS_SKD 回调好友列表 GetUserFriends ===> %s",jsonString);
|
|
userFriendsHandler(code,jsonString);//异步回调
|
|
userFriendsHandler(code,jsonString);//异步回调
|
|
}];
|
|
}];
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -573,25 +385,14 @@ void GetUserFriends(){
|
|
*/
|
|
*/
|
|
char * GetUserInfoJson(){
|
|
char * GetUserInfoJson(){
|
|
|
|
|
|
- NSLog(@"Unity 请求用户信息 GetUserInfoJson ===>>");
|
|
|
|
-
|
|
|
|
|
|
+// NSLog(@"Unity 请求用户信息 GetUserInfoJson ===>>");
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return MakeStringCopy("");
|
|
return MakeStringCopy("");
|
|
}else{
|
|
}else{
|
|
-
|
|
|
|
- NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSDictionary * user = jsonDict[@"user"];
|
|
|
|
-
|
|
|
|
- if (user!=nil){
|
|
|
|
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
- NSString * userJsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
- const char * cuschart =[userJsonString UTF8String];
|
|
|
|
- NSLog(@"IOS_SKD 回调用户信息 GetUserInfoJson ===> %@",userJsonString);
|
|
|
|
- //要先copy 不然c#调用free的时候回闪退
|
|
|
|
- return MakeStringCopy(cuschart);
|
|
|
|
- }else{
|
|
|
|
- return MakeStringCopy("");
|
|
|
|
- }
|
|
|
|
|
|
+ const char * cuschart = [[MYFactoryManager getUserInfo] UTF8String];
|
|
|
|
+ NSLog(@"IOS_SKD 回调用户信息 GetUserInfoJson ===> %@",[MYFactoryManager getUserInfo]);
|
|
|
|
+ //要先copy 不然c#调用free的时候回闪退
|
|
|
|
+ return MakeStringCopy(cuschart);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -602,6 +403,9 @@ void GetUserFriends(){
|
|
*/
|
|
*/
|
|
void DisConnectDevice(int type){
|
|
void DisConnectDevice(int type){
|
|
NSLog(@"Unity 请求断开蓝牙链接 disConnectDevice ===>>");
|
|
NSLog(@"Unity 请求断开蓝牙链接 disConnectDevice ===>>");
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -609,22 +413,17 @@ void DisConnectDevice(int type){
|
|
* friendid: 游戏好友ID
|
|
* friendid: 游戏好友ID
|
|
*/
|
|
*/
|
|
void InviteFriend(int friendid,char * info){
|
|
void InviteFriend(int friendid,char * info){
|
|
-
|
|
|
|
NSLog(@"Unity 点击邀请好友 InviteFriend ===>>");
|
|
NSLog(@"Unity 点击邀请好友 InviteFriend ===>>");
|
|
-
|
|
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
[HTTPDataProcession inviteFriends:friendid info:info inviteDataBlock:^(NSString *jsonString){
|
|
[HTTPDataProcession inviteFriends:friendid info:info inviteDataBlock:^(NSString *jsonString){
|
|
-
|
|
|
|
// NSLog(@"IOS_SKD 回调点击邀请好友事件 InviteFriend ===>>");
|
|
// NSLog(@"IOS_SKD 回调点击邀请好友事件 InviteFriend ===>>");
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[PopupView showCusHUDA:jsonString];
|
|
[PopupView showCusHUDA:jsonString];
|
|
});
|
|
});
|
|
|
|
|
|
}];
|
|
}];
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -636,27 +435,14 @@ void GetInviteInfo(){
|
|
NSLog(@"Unity获取好友邀请信息 GetInviteInfo ===>>");
|
|
NSLog(@"Unity获取好友邀请信息 GetInviteInfo ===>>");
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
- }else{
|
|
|
|
-
|
|
|
|
- NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSDictionary * invite = jsonDict[@"invite"];
|
|
|
|
- if (invite!=nil){
|
|
|
|
-
|
|
|
|
- //user字典 -> 字符串 -> Char
|
|
|
|
- NSDictionary * user = [invite objectForKey:@"user"];
|
|
|
|
- NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
- NSString * userString = [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
|
|
|
|
- const char * userChar =[userString UTF8String];
|
|
|
|
-
|
|
|
|
- //info字符串 -> Char
|
|
|
|
- NSString * info = invite[@"info"];
|
|
|
|
- const char * infoChar =[info UTF8String];
|
|
|
|
-
|
|
|
|
- NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>> %s , %s",userChar,infoChar);
|
|
|
|
- inviteFriendHandler(0,userChar,infoChar);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ //user字典 -> 字符串 -> Char
|
|
|
|
+ const char * userChar = [[MYFactoryManager getInviteUser] UTF8String];
|
|
|
|
+ //info字符串 -> Char
|
|
|
|
+ const char * infoChar =[[MYFactoryManager getInviteInfo] UTF8String];
|
|
|
|
+ NSLog(@"IOS_SKD 回调好友邀请信息 GetInviteInfo ===>> %s , %s",userChar,infoChar);
|
|
|
|
+ inviteFriendHandler(0,userChar,infoChar);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -664,6 +450,9 @@ void GetInviteInfo(){
|
|
*/
|
|
*/
|
|
void ScreenProjection(){
|
|
void ScreenProjection(){
|
|
NSLog(@"Unity 请求投屏事件 ScreenProjection ===>>");
|
|
NSLog(@"Unity 请求投屏事件 ScreenProjection ===>>");
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -672,6 +461,9 @@ void ScreenProjection(){
|
|
*/
|
|
*/
|
|
void ShowInviteFriend(int code, char * info){
|
|
void ShowInviteFriend(int code, char * info){
|
|
NSLog(@"Unity 请求打开好友列表弹窗 ShowInviteFriend ===>>");
|
|
NSLog(@"Unity 请求打开好友列表弹窗 ShowInviteFriend ===>>");
|
|
|
|
+ if ([instance existUserInfo]==NO){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -680,17 +472,21 @@ void ShowInviteFriend(int code, char * info){
|
|
*ios 请求完数据后用 PointerGetRankHandler 回调数据给unity
|
|
*ios 请求完数据后用 PointerGetRankHandler 回调数据给unity
|
|
*/
|
|
*/
|
|
void GetRank(int type){
|
|
void GetRank(int type){
|
|
-
|
|
|
|
- NSLog(@"Unity 获取榜单列表数据 GetRank ===>> %d",type);
|
|
|
|
|
|
+// NSLog(@"Unity 获取榜单列表数据 GetRank ===>> %d",type);
|
|
if ([instance existUserInfo]==NO){
|
|
if ([instance existUserInfo]==NO){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
[HTTPDataProcession GetRank:type rankDataBlock:^(const char *jsonString){
|
|
[HTTPDataProcession GetRank:type rankDataBlock:^(const char *jsonString){
|
|
-
|
|
|
|
NSLog(@"IOS_SKD 回调 榜单列表数据 GetRank ===>> %d %s",type,jsonString);
|
|
NSLog(@"IOS_SKD 回调 榜单列表数据 GetRank ===>> %d %s",type,jsonString);
|
|
-
|
|
|
|
getRankHandler(type,jsonString);
|
|
getRankHandler(type,jsonString);
|
|
-
|
|
|
|
}];
|
|
}];
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Unity call ios 获取鞋子角度
|
|
|
|
+*/
|
|
|
|
+int NativeGetAttX(int cusId){
|
|
|
|
+ return BTDataInstance.nativeAttX;
|
|
|
|
+}
|