// MyIOSSdk.m
# import "MyIOSSdk.h"
//這里引用SDK的頭文件
# import "SDKPlatform.h"
# if defined(__cplusplus)
extern "C" {
#endif
extern void UnitySendMessage( const char *, const char *, const char *);
extern NSString* _CreateNSString ( const char * string);
# if defined(__cplusplus)
}
#endif
//*****************************************************************************
@implementation MyIOSSdk
//**********************
//message tools
+ ( void )sendU3dMessage:(NSString *)messageName param:(NSDictionary *)dict
{
NSString *param = @ "" ;
if ( nil != dict ) {
for (NSString *key in dict)
{
if ([param length] == 0 )
{
param = [param stringByAppendingFormat:@ "%@=%@" , key, [dict valueForKey:key]];
}
else
{
param = [param stringByAppendingFormat:@ "&%@=%@" , key, [dict valueForKey:key]];
}
}
}
UnitySendMessage( "SDK_Object" , [messageName UTF8String], [param UTF8String]);
}
//**********************
//SDK fun
//初始化SDK
-( void )SDKInit
{
SDKcfg *cfg = [[[SDKcfg alloc] init] autorelease];
cfg.appid = 123456 ;
cfg.appKey =@ "aoaoaoaoaoaoaoaoaoaoaoaoaaoaoaoaoaoaoao" ;
cfg.orientation = UIDeviceOrientationLandscapeLeft;
//調(diào)用SDK的初始化函數(shù)
[[SDKPlatform defaultPlatform] SDKInit:cfg];
//添加回調(diào)監(jiān)聽
[[SDKPlatform defaultPlatform] addObserver:self selector: @selector (SNSInitResult:) name:(NSString *)kInitNotification object:nil];
}
//獲取用戶ID
-(NSString*)SDKGetUserID
{
[[SDKPlatform defaultPlatform] SDKGetUserID];
}
//**********************
//call back fun
//初始化更新回調(diào)
- ( void )SNSInitResult:(NSNotification *)notify
{
[MyIOSSdk sendU3dMessage:@ "SDKMsgInit" param:nil];
}
@end
//*****************************************************************************
# if defined(__cplusplus)
extern "C" {
#endif
//字符串轉(zhuǎn)化的工具函數(shù)
NSString* _CreateNSString ( const char * string)
{
if (string)
return [NSString stringWithUTF8String: string];
else
return [NSString stringWithUTF8String: "" ];
}
char * _MakeStringCopy( const char * string)
{
if (NULL == string) {
return NULL;
}
char * res = ( char *)malloc(strlen(string)+ 1 );
strcpy(res, string);
return res;
}
static MyIOSSdk *mySDK;
//供u3d調(diào)用的c函數(shù)
void _PlatformInit()
{
if (mySDK==NULL)
{
mySDK = [[MyIOSSdk alloc]init];
}
[lsSDK SDKInit];
}
//注意這個函數(shù)是返回字符串
const char * _PlatformGetUin()
{
if (lsSDK==NULL)
{
lsSDK = [[MyIOSSdk alloc]init];
}
return _MakeStringCopy([[lsSDK SDKGetUserID] UTF8String]);
}
# if defined(__cplusplus)
}
#endif
|