123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672 |
- //
- // IOSPlatformSDK.m
- // OYGameSKD
- //
- // Created by leon on 2021/1/21.
- // Copyright © 2021 Oujia. All rights reserved.
- #import "IOSPlatformSDK.h"
- #pragma mark ============================>> ios call unity C语言指针声明 start
- /**
- *运动数据
- * left: 左鞋动作代码
- * right: 右鞋动作代码
- * 对应 enum CMD_MOTION
- */
- typedef void (* MotionHandler) (int cusid, int left, int right);
- /**
- * 踏步状态,频率
- * leftStatus: 左鞋(0:停止, 1:慢,2:快)
- * rightStatus: 右鞋(0:停止, 1:慢,2:快)
- * leftFrag: 左鞋(每分钟步频)
- * rightFrag: 右鞋(每分钟步频)
- */
- typedef void (* StepHandler)(int cusid, int leftStatus, int rightStatus, int leftFrag, int rightFrag);
- /**
- * 返回蓝牙设备的基本信息,用于界面上显示当前的设备状况,app 跳转的时候传过来的
- * name: 设备名称
- * status: 设备状态 @see enum BLE_STATE
- * electricity: 设备电量 取值范围[0 - 100] 对比左右鞋 handler较低的电量
- */
- typedef void (* DeviceHandler)(int cusid, const char *name, const char *address, int status, int electricity);
- /**
- * 好友列表 unity call ios 异步请求数据后 ios call unity
- * 调用api GetUserFriends() 的回调
- * code: 请求结果代码 0: 成功, 非0: 根据业务处理
- * json: 好友列表数据 , json 数组
- *
- */
- typedef void (* UserFriendsHandler)(int code, const char * json);
- /**
- * 调用api GetUserFriends() 的回调
- * code: 请求结果代码 0: 成功, 非0: 根据业务处理
- * json: 好友列表数据 , json 数组
- */
- typedef void (* InviteFriendHandler)(int code, const char * userJson, const char * inviteInfo);//
- /**
- *游戏首页交互动作的回调
- * cusid: 主副设备
- * code: 交互代码
- */
- typedef void (* ActionHandler) (int cusid, int code);
- /**
- * 游戏榜单数据回调
- * cusid: 主副设备
- * code: 交互代码
- */
- 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
- @implementation IOSPlatformSDK
- #pragma mark ============================>> SDK 单例
- static IOSPlatformSDK * instance;
- +(instancetype)sharedInstance{
- return [[self alloc] init];
- }
- + (instancetype)allocWithZone:(struct _NSZone *)zone{
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- instance = [super allocWithZone:zone];
- });
- return instance;
- }
- - (instancetype)init{
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- instance = [super init];
- [self initNotification];
- });
- return instance;
- }
- #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)gameEndInitData:(NSNotification*)notification{
- [[BTDataProcess sharedInstance] gameEndInitData];
- NSLog(@"unity call ios 通知结束游戏 --> IOSPlatformSDK");
- }
- //通知弹出蓝牙搜索框
- -(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 缓存处理
- //是否已经缓存到用户信息
- -(BOOL)existUserInfo{
-
- NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
- if (jsonDict==nil){
- // [PopupView showCusHUDA:@"获取趣动用户数据失败"];
- return YES;
- }else{
- 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
- -(void)bridgingMotionAction:(int)cusid
- left:(int)left
- right:(int)right{
- if (motionHandler!=nil){
- motionHandler(cusid,left,right);
- }
- }
- -(void)bridgingStepAction:(int)cusid
- leftStatus:(int)leftStatus
- rightStatus:(int)rightStatus
- leftFrag:(int)leftFrag
- rightFrag:(int)rightFrag{
- // NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
- stepHandler(cusid,leftStatus,rightStatus,leftFrag,rightFrag);
- }
- -(void)bridgingDeviceAction:(int)cusid
- name:(NSString*)name
- address:(NSString*)address
- status:(int)status
- electricity:(int)electricity{
- // NSLog(@"deviceHandler ===>> %d %@ %@ %d %d",cusid,name,address,status,electricity);
- //
- const char * charName =[name UTF8String];
- const char * charAddress =[address UTF8String];
- if (deviceHandler != nil) {
- deviceHandler(cusid,charName,charAddress,status,electricity);
- }
-
- }
- -(void)bridgingInteraction:(int)cusid
- code:(int)code{
- //传给unity ---> 旧版游戏未用到
- // actionHandler(cusid,code);
- }
- @end
- #pragma mark ============================>> unity call ios
- /**
- * c语言字符串指针malloc
- */
- char* MakeStringCopy(const char* string){
-
- if (string == NULL)
- return NULL;
- char* res = (char*)malloc(strlen(string) + 1);
- strcpy(res, string);
- return res;
-
- }
- /**
- * unity call ios 主动接收 函数指针
- * MotionHandler 用于ios回调 "蓝牙动作",在👆🏻bridgingMotionAction中实现
- */
- extern "C" {void PointerMotionHandler(MotionHandler handler){
- motionHandler = handler;
- NSLog(@"PutIntPtr MotionHandler 指针内存地址 ===>> %p",&motionHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * StepHandler 用于ios回调 "鞋子步频",在👆🏻bridgingStepAction中实现
- */
- extern "C" { void PointerStepHandler(StepHandler handler){
- stepHandler = handler;
- NSLog(@"PutIntPtr StepHandler 指针内存地址 ===>> %p",&stepHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * StepHandler 用于ios回调 "鞋子蓝牙状态和电量",在👆🏻bridgingDeviceAction中实现
- */
- extern "C" {void PointerDeviceHandler(DeviceHandler handler){
- deviceHandler = handler;
- NSLog(@"PutIntPtr DeviceHandler 指针内存地址 ===>> %p",&deviceHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * ActionHandler 用于ios回调“”蓝牙和游戏大厅交互动作数据”,在👆🏻bridgingMotionAction中实现
- */
- extern "C" {void PointerActionHandler(ActionHandler handler){
- actionHandler = handler;
- NSLog(@"PutIntPtr UserFsHandler 指针内存地址 ===>> %p",&actionHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * UserFriendsHandler 用于ios回调 "当前用户好友列表",在👇🏻GetUserFriends中实现
- */
- extern "C" {void PointerUserFriendsHandler(UserFriendsHandler handler){
- userFriendsHandler = handler;
- NSLog(@"PutIntPtr UserFsHandler 指针内存地址 ===>> %p",&userFriendsHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * InviteFriendHandler 用于ios回调 "接收好友邀请" ,在👇🏻GetInviteInfo中实现
- */
- extern "C" {void PointerInviteFriendHandler(InviteFriendHandler handler){
- inviteFriendHandler = handler;
- NSLog(@"PutIntPtr UserFsHandler 指针内存地址 ===>> %p",&inviteFriendHandler);
- }
- }
- /**
- * unity call ios 主动接收 函数指针
- * InviteFriendHandler 用于ios回调 "接收好友邀请" ,在👇🏻GetInviteInfo中实现
- */
- extern "C" {void PointerGetRankHandler(GetRankHandler handler){
- getRankHandler = handler;
- NSLog(@"PutIntPtr GetRankHandler 指针内存地址 ===>> %p",&getRankHandler);
- }
- }
- /**
- * 游戏开始
- */
- void GameStart(){
-
- NSLog(@"Unity 请求开始游戏 GameStart ===>>");
- if ([instance existUserInfo]==NO){
- return;
- }
-
- [CUS_NOTIFICATIONCENTER postNotificationName:@"gameStartInitData" object:nil];
- [HTTPDataProcession gameStart];
- }
- /**
- * 游戏结束
- * level: level
- * score: score
- * record: record
- * mode: mode
- * opponentId: 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);
-
- if ([instance existUserInfo]==NO){
- return;
- }
-
- [CUS_NOTIFICATIONCENTER postNotificationName:@"gameEndInitData" object:nil];
- [HTTPDataProcession gameEnd];
- //上传数据
- [HTTPDataProcession postGameRecord:level score:score record:record mode:mode opponentId:opponentId gameEndDataBlock:^(NSString *jsonString){
- NSLog(@"IOS_SKD 回调结束游戏请求 GameEnd ===> %@",jsonString);
- }];
-
- }
- /**
- * 搜索设备
- * type: 设备ID
- */
- void SearchDevice(int type){
- //unity 有两个search按钮 type 0是主设备 1是副设备
- NSDictionary * dict = @{@"type":@(type)};
- NSLog(@"Unity 请求搜索设备 SearchDevice ===>> %@",dict);
- [CUS_NOTIFICATIONCENTER postNotificationName:@"searchBLEAction" object:nil userInfo:dict];
- }
- /**
- * 链接设备
- * type: 设备ID
- */
- void ConnectDevice(int type){
- NSLog(@"Unity 请求链接设备 ConnectDevice ===>> %d",type);
- //unity 有两个connect按钮 type 0是第一个玩家 1是第二个玩家
- }
- /**
- * 震动
- * type: 设备ID
- * duration: 时长 ms [100 .. 1000]
- */
- 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];
- }
- /**
- * unity获取用户好友列表 -->> ios端根据用户token值请求http好友列表 ios将列表json的数组数据传给unity
- */
- void GetUserFriends(){
-
- NSLog(@"Unity 请求好友列表 GetUserFriends ===>>");
- if ([instance existUserInfo]==NO){
- return;
- }
-
- [HTTPDataProcession getFriendsList:^(int code, const char *jsonString){
- NSLog(@"IOS_SKD 回调好友列表 GetUserFriends ===> %s",jsonString);
- userFriendsHandler(code,jsonString);//异步回调
- }];
- }
- /**
- * unity获取用户信息 -->> 解析从Spotr App的传过来的RL_Seme ios返回json数据给游戏
- */
- char * GetUserInfoJson(){
-
- NSLog(@"Unity 请求用户信息 GetUserInfoJson ===>>");
- if ([instance existUserInfo]==NO){
- return MakeStringCopy("");
- }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("");
- }
-
- }
-
- }
- /**
- * unity可以主动断开链接
- * type: 设备类型 0: 主, 1: 副
- */
- void DisConnectDevice(int type){
- NSLog(@"Unity 请求断开蓝牙链接 disConnectDevice ===>>");
- }
- /**
- * 主动邀请好友
- * friendid: 游戏好友ID
- */
- void InviteFriend(int friendid,char * info){
-
- NSLog(@"Unity 点击邀请好友 InviteFriend ===>>");
- if ([instance existUserInfo]==NO){
- return;
- }
- [HTTPDataProcession inviteFriends:friendid info:info inviteDataBlock:^(NSString *jsonString){
-
- // NSLog(@"IOS_SKD 回调点击邀请好友事件 InviteFriend ===>>");
- dispatch_async(dispatch_get_main_queue(), ^{
- [PopupView showCusHUDA:jsonString];
- });
-
- }];
-
- }
- /**
- * unity界面准备好后可以申请邀请信息,回调在inviteFriendHandler
- * friendid: 游戏好友ID
- */
- void GetInviteInfo(){
-
- NSLog(@"Unity获取好友邀请信息 GetInviteInfo ===>>");
- return;
- if ([instance existUserInfo]==NO){
-
- 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);
-
- }
- }
- }
- /**
- * 投屏
- */
- void ScreenProjection(){
- NSLog(@"Unity 请求投屏事件 ScreenProjection ===>>");
- }
- /**
- * Unity call ios 弹出邀请好友弹窗
- * 旧版游戏暂未用到
- */
- void ShowInviteFriend(int code, char * info){
- NSLog(@"Unity 请求打开好友列表弹窗 ShowInviteFriend ===>>");
- }
- /**
- * Unity call ios 获取游戏榜单数据
- *if (type == 0) "world" else "friend"
- *ios 请求完数据后用 PointerGetRankHandler 回调数据给unity
- */
- void GetRank(int type){
-
- NSLog(@"Unity 获取榜单列表数据 GetRank ===>> %d",type);
- if ([instance existUserInfo]==NO){
- return;
- }
- [HTTPDataProcession GetRank:type rankDataBlock:^(const char *jsonString){
-
- NSLog(@"IOS_SKD 回调 榜单列表数据 GetRank ===>> %d %s",type,jsonString);
- getRankHandler(type,jsonString);
-
- }];
- }
|