当前位置:编程学习 > wap >>

uc sdk monotouch应用

近来又开始对接UC的SDK对他应用到monodevelop平台上面的时候也是会有一些问题。这里面是写的源代码。我们先看一下生成.a的工程文件
//
//  UseStaticLibraryUc.h
//  UseStaticLibraryUc
//
//  Created by huangyushi on 13-1-22.
//  Copyright (c) 2013年 huangyushi. All rights reserved.
//
 
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <pthread.h>
#import "UCGameSdk.h"
#import "UCGameSdkConst.h"
#import "StaticLibraryManager.h"
 
typedef NSString* (^charge_cb) (NSInteger nType);
 
typedef struct{
    int         _roleid;
    NSString*   _rolename;
    NSString* _customInfo;
}product_t;
 
 
@inte易做图ce UseStaticLibraryUc : UIViewController<UCGameSdkProtocol>
 
//加载
- (void)viewDidLoad;
- (void)viewDidUnload;
 
//登陆部分
- (void)onSdkInitFin: (NSNotification *) notification;
- (void)onLoginFin: (NSNotification *) notification;
- (void)onUnloginExit;
 
//支付部分
- (void)onPayFin: (NSNotification *) notification;
- (void)payExit: (NSNotification *) notification;
- (void)buy:(NSInteger )roleId RoleName:(NSString* )roleName customInfo:(NSString* )customInfo;
 
//封装对外接口
+(UseStaticLibraryUc* )Isrance;
-(void)setInitComplete:(charge_cb)complete;
-(void)loginUC:(charge_cb)suc Fail:(charge_cb)fail Cancel:(charge_cb)cancel;
-(void)buyUC:(NSInteger )_roleId RoleName:(NSString* )_roleName customInfo:(NSString* )_customInfo Success:(charge_cb)suc Fail:(charge_cb)fail Cancel:(charge_cb)cancel;
-(void)setConnectFunc:(charge_cb)sd Rec:(charge_cb)rec Packet:(charge_cb)packet;
-(NSString* )getUserName;
-(NSString* )getUserPasswd;
-(NSString* )getSid;
@end
 
 
//
//  UseStaticLibraryUc.m
//  UseStaticLibraryUc
//
//  Created by huangyushi on 13-1-22.
//  Copyright (c) 2013年 huangyushi. All rights reserved.
//
 
#import "UseStaticLibraryUc.h"
 
static charge_cb    call_backs[10] = {NULL};
static NSString*    game_user =NULL;
static NSString*    game_passwd =NULL;
 
//游戏帐号登录需要用到的变量
static  pthread_cond_t  thread_cond =PTHREAD_COND_INITIALIZER;
static  pthread_mutex_t thread_lock =PTHREAD_MUTEX_INITIALIZER;
static  pthread_t       connect_to_our_server =0;
static  NSString*       ucsid =NULL;
 
static NSMutableDictionary *resultDict;
 
void* wait_for_cour_server_replay(void* arg)
{
    ucsid = NULL;
    while (true)
    {
        if (call_backs[connect_packet] !=NULL) {
            call_backs[connect_packet](connect_packet);
        }
        if (call_backs[Connect_receive] !=NULL) {
            if (call_backs[Connect_receive](Connect_receive) !=NULL) {
                ucsid = [NSStringstringWithFormat:@"%@",call_backs[Connect_receive](Connect_receive)];
                if (ucsid ==@"error") {
                    [resultDictsetValue:[NSNumber numberWithInt:1]forKey:@"resultCode"];
                    [resultDict setValue:@"帐号或密码错误,请重新输入." forKey:@"resultMsg"];
                    pthread_cond_signal(&thread_cond);//唤醒阻塞的线程
                    break;
                }
            }
        }
        if(NULL != ucsid){
            int resultCode = 0;
            [resultDict setValue:ucsid forKey:@"sid"];
            [resultDict setValue: [NSNumbernumberWithInt : resultCode] forKey:@"resultCode"];
            [resultDict setValue:@"OK"forKey:@"resultMsg"];
            
            pthread_cond_signal(&thread_cond);//唤醒阻塞的线程
            break;
        }
    }
    return NULL;
}
 
@implementation UseStaticLibraryUc
- (void)viewDidUnload{
}
 
-(void)viewDidLoad
{
}
 
//登陆部分
-(id)init
{
    self = [super init];
    if(NULL != self)
    {
        [[NSNotificationCenterdefaultCenter] removeObserver:self];
        //添加 Observer来监听 SDK 初始化事件,以便在 SDK初始化完成时进行后续处理。
        [[NSNotificationCenterdefaultCenter] addObserver:self
                                                 selector:@selector(onSdkInitFin:)
                                                     name:UCG_SDK_MSG_SDK_INIT_FIN
                                                   object:nil];
        //设置游戏相关参数
        UCGameSdk *sdk = [UCGameSdkdefaultSDK];
        /** 设置游戏相关参数*/
        //正式
        //        sdk.cpId = 593;    // 设置游戏合作商编号,该编号在游戏接入时由 UC 分配
        //        sdk.gameId = 105539; // 设置游戏编号,该编号在游戏接入时由 UC 分配
        //        sdk.serverId= 1245;   // 设置游戏服务器 ID,该编号由所在的游戏分区决定
        
        //测试
        sdk.cpId =1;    // 设置游戏合作商编号,该编号在游戏接
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,