Unity接IOS的SDK

3 篇文章 0 订阅

代码是仿照以前同事接IOS接的SDK

头文件

#import <Foundation/Foundation.h>

#if defined(__cplusplus)
extern "C"
{
#endif

    //用于Unity的调用(Unity只能调用C的方法,调不到OC的方法)

    extern void  PlatformInit();
    extern void  PlatformLogin();
    
#if defined(__cplusplus)
}
#endif

源文件

#import <Foundation/Foundation.h>
#import "EGLSSDK_Framework/EGLSSDK.h"
#import "EGLSPlatformSDK.h"
#import "JSONKit.h"
#if defined(__cplusplus)
extern "C"
{
#endif
    extern void UnitySendMessage(const char *,const char *,const char *);
#if defined(__cplusplus)
}
#endif

//这里是代理的实现,没有太明白,我感觉写不写都可以
@interface  EGLSPlatformSDK:NSObject<EGLSSDKDelegate>

@end

@implementation EGLSPlatformSDK
-(id)init
{
    self = [super init];
    if(self)
    {
        
    }
    return self;
}
+(id) instance //单利
{
    static EGLSPlatformSDK * instance = nil;
    if (instance == nil)
    {
        @synchronized(self)
        {
            if (instance == nil) {
                instance = [[self alloc] init];
            }
        }
    }
    return instance;
}


-(void)SdkInit
{
    NSLog(@"SDK  Init-------------这里调用SDK的方法,成功");
}
-(void)SdkLogin
{
    NSLog(@"SDK Login-------------这里调用SDK的方法,成功");
    
}
-(void)SdkPay : (NSString *) productID withExtraData:(NSString *)extraData
{
    NSLog(@"SDK Pay-------------这里调用SDK的方法,成功");
}

// 这里是实现代理,这个看你sdk的方法写。
- (void)registerSuccessCallBackWithUid:(NSString *)uid{
    NSLog(@"-------------EGLS registerSuccessCallBackWithUid\n uid is %@",uid);
}

- (void)loginSuccessCallBackWithUid:(NSString *)uid andToken:(NSString *)token andChannel:(NSString *)channel{
    NSLog(@"-------------EGLS Login Success Cal l Back!\n uid is : %@\n token is : %@\n channel is : %@", uid, token,channel);
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        
        dic[@"uid"] = uid;
        dic[@"access_token"] = token;
        dic[@"name"] = channel;
        UnitySendMessage("0", "OnSDKLogin", [dic JSONString].UTF8String);//登录成功发消息给Unity,结果android的都应该知道。
}

- (void)loginCancel {
    NSLog(@"-------------EGLS loginCancel");
}
-(void)FBloginSuccessCallBackWithUid:(NSString *)uid name:(NSString *)name picture:(NSString *)picture{
    NSLog(@"-------------EGLS FBloginSuccessCallBackWithUid");
}
-(void)FBloginSuccessCallBackWithFields:(NSArray *)fields{
    NSLog(@"-------------EGLS FBloginSuccessCallBackWithFields");
}
//
-(void)applePurchaseSuccessCallBackWithOrderID:(NSString *)orderID andMoney:(NSString *)money{
    NSLog(@"-------------EGLS applePurchaseSuccessCallBackWithOrderID,order id is %@,money is %@",
          orderID,money);
}

//Unity调用下边的方法,这些方法调用SDK。
//初始化
void PlatformInit()
{
    [[EGLSPlatformSDK instance]SdkInit];
}
//登录
void PlatformLogin()
{
    [[EGLSPlatformSDK instance]SdkLogin];
}
//支付
void PlatformPay(const char *productID,const char *extraData)
{
    NSLog(@"-------------PlatformPay,productID id is %@,extraData is %@",[NSString stringWithUTF8String:productID] ,[NSString stringWithUTF8String:extraData]);
    [[EGLSPlatformSDK instance]SdkPay:[NSString stringWithUTF8String:productID] withExtraData:[NSString stringWithUTF8String:extraData]];
}

@end


JSONKit,好像是开源的,别人发给我的。

链接: https://pan.baidu.com/s/1o8abk7o 密码: qkp7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值