代码是仿照以前同事接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