Uc sdk monotouch Application

Source: Internet
Author: User

Recently, the integration with the uc sdk also has some problems when he applies it to the monodevelop platform. The source code is written here. Let's take a look at the generation. a project file // 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; @ interface UseStaticLibraryUc: UIViewController <UCGameSdkProtocol> // load-(void) viewDidLoad;-(void) viewDidUnload; // login part-(void) onSdkInitFin: (NSNotification *) notification;-(void) onLoginFin: (NSNotification *) notification;-(void) onUnloginExit; // payment part-(void) onPayFin: (NSNotification *) notification;-(void) payExit: (NSNotification *) notification; -(Void) buy :( NSInteger) roleId RoleName :( NSString *) roleName customInfo :( NSString *) customInfo; // encapsulate external interface + (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 Can Cel :( 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; // variable static pthread_cond_t thread_cond = required for game account logon; static thread_lock = required; 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: @ "incorrect account or password. Please enter it again. "forKey: @" resultMsg "]; pthread_cond_signal (& thread_cond); // wake up the blocked thread 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); // wake up the blocked thread break;} return NULL ;} @ implementation UseStaticLibraryUc-(void) viewDidUnload {}-(void) viewDidLoad {} // login part-(id) init {self = [super init]; if (NULL! = Self) {[[nsnotificationcenterdefacenter] removeObserver: self]; // Add an Observer to listen for SDK initialization events, so that subsequent processing is performed when SDK Initialization is complete. [[Nsnotifcencenterdefacenter] addObserver: self selector: @ selector (onSdkInitFin :) name: jsonobject: nil]; // set the game-related parameter UCGameSdk * sdk = [ucgamesdkultsdk sdk]; /** set game-related parameters * // official // sdk. cpId = 593; // set the game partner number, which is allocated by the UC when the game is connected. // sdk. gameId = 105539; // set the game number, which is allocated by the UC when the game is connected. // sdk. serverId = 1245; // set the game server ID, which is determined by the game partition. // test the sdk. cpId = 1; // set the game partner number, which is allocated by UC during game access Sdk. gameId = 176; // set the game number. During Game access, the UC assigns the sdk. serverId = 180; // set the game server ID, which is determined by the game partition. // set the joint test mode or official production mode: YES: joint test mode, the SDK is automatically connected to the joint test environment of the SDK platform. NO: in the formal production mode, the SDK is automatically connected to the formal production environment of the SDK platform. Sdk. isDebug = YES; sdk. gameUserName = @ "dingting hall official account"; sdk. allowGameUserLogin = YES; // set the game additional information ExInfo * exInfo = [[ExInfoalloc] init] autorelease]; exInfo. cpServiceContact = @ "ding Tang \ n Customer Service Tel: 021-50183061"; sdk. exInfo = exInfo; [sdk initSDK]; NSLog (@ "Access to UC_SDK initialization");} return self ;}// SDK initialization listening handler function-(void) onSdkInitFin: (NSNotification *) notification {[[nsnotificationcenterdefacenter] removeObserver: selfna Me: UCG_SDK_MSG_SDK_INIT_FINobject: nil]; // read the initialization result data NSDictionary * res = notification. userInfo; NSNumber * code = (NSNumber *) [resobjectForKey: @ "code"]; // judge the value of the received code, determine whether the SDK is successfully initialized. // if the code is 1, the SDK initialization fails. if the value is 0, the SDK initialization succeeds. if ([code intValue] = 1) {NSLog (@ "failed to listen to initialization"); return;} NSLog (@ "successful listening to initialization"); if (NULL! = Call_backs [init_complete]) {call_backs [init_complete] (init_complete);} [[distinct] removeObserver: self name: jsonobject: nil]; [[distinct] removeObserver: self name: UCG_SDK_MSG_EXIT_WITHOUT_LOGIN object: nil]; // Add an Observer to listen to the SDK Logon Message [[nsicationicationcenterdefacenter] addObserver: self selector: @ selector (onLoginFin :) name: UCG_S DK_MSG_LOGIN_FINobject: nil]; // when an Observer is added to listen to the SDK, the [[nsnotificationcenterdefacenter] addObserver: self selector: @ selector (onUnloginExit) name: Handler: nil] is returned. [[nsnotifcencenterdefacenter] removeObserver: self name: jsonobject: nil]; [nsnotifcencenterdefacenter] removeObserver: self name: UCG_SDK_MSG_PAY_EXIT object: nil]; [NSNot Ificationcenterdefadefacenter] addObserver: self selector: @ selector (onPayFin :) name: Usage: nil]; [[nsicationicationcenterdefacenter] addObserver: self selector: @ selector (payExit :) name: Usage: nil];} // log on to the UC account-(void) onLoginFin: (NSNotification *) notification {// read the logon result data NSDictionary * res = notification. userInfo; NSNumber * code = (NSNumber *) [resobjectForKey :@ "Code"]; // determines the value of the received code. if the SDK is successfully logged on, // if the code is 0, the logon succeeds. if the code is 1, the logon fails. if (code. intValue = 0) {NSLog (@ "successfully logged on"); if (NULL! = Call_backs [Login_success]) {call_backs [Login_success] (Login_success); call_backs [Login_success] = NULL ;}} else {NSLog (@ "Logon Failed"); if! = Call_backs [Login_fail]) {call_backs [Login_fail] (Login_fail); call_backs [Login_fail] = NULL ;}} NSLog (@ "");} // call this function to exit the logon interface without logon-(void) onUnloginExit {NSLog (@ "Listening to games not logged back "); if (NULL! = Call_backs [Login_fail]) {call_backs [callback] (Login_fail); call_backs [callback] = NULL ;}}-(NSDictionary *) callback :( NSString *) gameUser gamePassword :( NSString *) gamePassword {NSLog (@ "thread start"); // open the thread and block the current line holding pthread_cond_init (& thread_cond, NULL); pthread_mutex_init (& thread_lock, NULL ); // send the username and password to our server pthread_mutex_lock (& thread_lock); resultDict = [[[NSMutableDictionaryalloc] init] aut Orelease]; game_user = gameUser; game_passwd = gamePassword; if (NULL! = Call_backs [Connect_send]) {call_backs [Connect_send] (Connect_send);} // func pthread_create (& connect_to_our_server, NULL, callback, NULL); terminate (& thread_cond, & thread_lock ); pthread_mutex_unlock (& thread_lock); // run the following command to recycle pthread_join (connect_to_our_server, NULL) Wait (& thread_lock); pthread_cond_destroy (& thread_cond ); NSLog (@ "string after appen D is111111111111111111 % @ ", ucsid); returnresultDict;}-(void) buy :( NSInteger) _ roleId RoleName :( NSString *) _ roleName customInfo :( NSString *) _ customInfo {char order [200]; constchar * char_content = [_ encoding: NSASCIIStringEncoding]; sprintf (order, "% s", char_content); NSString * customInfo = [nsstringstringwithuf8string: order]; NSString * roleId = [NSStringstringWithFormat: @ "% d ", _ RoleId]; NSString * roleName = _ roleName; NSDictionary * dict = [role: [NSNumber numberWithBool: YES], @ "allowContinuousPay", customInfo, @ "customInfo", roleId, @ "roleId", roleName, @ "roleName", nil]; [[UCGameSdk defaultSDK] payWithPaymentInfo: dict];}-(void) onPayFin: (NSNotification *) notification {NSDictionary * res = notification. userInfo; NSNumber * code = (NSN Umber *) [resobjectForKey: @ "code"]; if (code. intValue = 0) {if (NULL! = Call_backs [Buy_success]) {call_backs [Buy_success] (Buy_success); call_backs [Buy_success] = NULL ;}} else {if (NULL! = Call_backs [Buy_fail]) {call_backs [Buy_fail] (Buy_fail); call_backs [Buy_fail] = NULL ;}}-(void) payExit: (NSNotification *) notification {}/***** static library external interface */static UseStaticLibraryUc * instance = nil; + (UseStaticLibraryUc *) Isrance {if (instance = nil) {instance = [[UseStaticLibraryUcalloc] init];} returninstance;}-(void) setInitComplete :( charge_cb) complete {call_backs [init_complete] = [completeco Py];}-(void) loginUC :( charge_cb) suc Fail :( charge_cb) fail Cancel :( charge_cb) cancel {call_backs [Login_success] = [succopy]; call_backs [Login_fail] = [failcopy]; call_backs [Login_cancel] = [cancelcopy]; NSLog (@ "click the logon button"); [[UCGameSdk defaultSDK] loginWithDelegate: self]; // [[UCGameSdk defasdk SDK] login];}-(void) buyUC :( NSInteger) _ roleId RoleName :( NSString *) _ roleName customInfo :( NSString *) _ customInfo Success :( charge_cb) suc Fail :( charge_cb) fail Cancel :( charge_cb) cancel {NSLog (@ "go to buyUC"); call_backs [Buy_success] = [succopy]; call_backs [Buy_fail] = [failcopy]; call_backs [Buy_cancel] = [cancelcopy]; NSLog (@ "running to call buy"); [instance buy: _ roleId RoleName: _ roleName customInfo: _ customInfo]; NSLog (@ "the buy call enters");}-(void) setConnectFunc :( charge_cb) sd Rec :( charge_cb) rec Packet :( charge_cb) packet {call_backs [Connect_send] = [sdcopy]; call_backs [Connect_receive] = [reccopy]; call_backs [connect_packet] = [packetcopy];}-(NSString *) getUserName {returngame_user ;} -(NSString *) getUserPasswd {returngame_passwd;}-(NSString *) getSid {return [[ucgamesdkdefasdk SDK] sid];} @ end // bind to public delegate NSString XMUtilityCallback (int nType) in monotouch; [BaseType (typeof (UIViewController), Delegates = new string [] {"UCGam ESdkProtocol "})] interface UseStaticLibraryUc {[Static, Export (" Isrance ")] UseStaticLibraryUc Isrance (); [Export (" setInitComplete: ")] string setInitComplete (complete ); // specify response parameters [Export ("loginUC: Fail: Cancel:")] void loginUC (XMUtilityCallback suc, failed fail, XMUtilityCallback cancel); [Export ("buyUC: RoleName: customInfo: Success: Fail: Cancel: ")] void buyUC (int _ roleId, stri Ng _ roleName, string _ customInfo, XMUtilityCallback suc, XMUtilityCallback fail, XMUtilityCallback cancel); [Export ("setConnectFunc: Rec: Packet:")] void setConnectFunc (callback sd, callback rec, XMUtilityCallback packet); [Export ("getUserName")] string getUserNameUC (); [Export ("getUserPasswd")] string getUserPasswdUC (); [Export ("getSid")] there is a problem in string getSidUC ();} That I have never understood why. When using the uc sdk, the function in the static library calls our callback function. In its callback function implementation, we cannot use breakpoints or create threads. I have been investigating and found that it was a signal thing. I heard the UC technical staff say this is an error signal. Then we asked him to go, but instead we could. There has never been a clear answer, because of the time relationship, there is no in-depth cloud research.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.