// // ViewController.m // FreeSDKDebug // // Created by 韩凯 on 7/10/15. // Copyright (c) 2015 江苏易乐网络科技有限公司. All rights reserved. // #import "ViewController.h" #import "FreeSDK.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *bindPhoneLabel; @end @implementation ViewController - (IBAction)isCanPay:(id)sender { [FreeSDK isCanPay:^(BOOL isCanPay, NSString *msg) { NSLog(@"is can pay %d, msg %@", isCanPay, msg); [[[UIAlertView alloc] initWithTitle:@"测试是否可以支付" message: isCanPay ? @"可以支付" : msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show]; }]; } - (IBAction)showRealNameRegister:(id)sender { [FreeSDK showRealNameAuthentication:self]; } - (void)viewDidLoad { [super viewDidLoad]; //120055340 1511171001 [FreeSDK initSDKWithAppId:@"1213113243" withSDKBlock:^(YLSDKType type, NSString *msg) { switch (type) { case YLSDKTypeInitSuccess: NSLog(@"初始化成功"); break; case YLSDKTypeInitFailure: NSLog(@"初始化失败"); break; case YLSDKTypeSwitchAccount: NSLog(@"切换账号成功,需重启游戏!"); [FreeSDK logout]; self.bindPhoneLabel.text = accountIdLabel.text = tokenLabel.text = tokenExpiryLabel.text = nil; [self loginOrLogout:self]; break; } }]; [FreeSDK setupWeChatAppId:@"wx52c39e71978b58d5" appSecret:@"0bdf260bc8057e7c9df4f93661cb7255"]; [FreeSDK setupQQAppId:@"1106176954"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogin) name:YLUserDidLoginNotification object:nil]; // if ([YLAccount sharedInstance].loggedIn) { // [self userDidLogin]; // } } - (void)userDidLogin { YLAccount * acc = [YLAccount sharedInstance]; accountIdLabel.text = acc.identifier; tokenLabel.text = acc.token; NSDateFormatter * fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss"; tokenExpiryLabel.text = [fmt stringFromDate:acc.tokenExpiry]; // self.bindPhoneLabel.text = acc.phoneNumber; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (BOOL)prefersStatusBarHidden { return YES; } - (IBAction)loginOrLogout:(id)sender { if ([YLAccount sharedInstance].loggedIn) { #warning logout and delete cache [FreeSDK logout]; self.bindPhoneLabel.text = accountIdLabel.text = tokenLabel.text = tokenExpiryLabel.text = nil; } else { [FreeSDK presentLoginDialog:nil]; } } - (IBAction)pay:(id)sender { YLOrder *order=[[YLOrder new]init]; order.title=@"Test Payment"; order.cpInfo=@"com.game003.zhyry.6"; order.cpOrderId=@"1213113243"; order.total=0.01f; [FreeSDK pay:order]; } - (void)purchase:(id)sender { NSInteger randomId = (NSInteger)(arc4random() % (1999 - 1000) + 1000); NSString * oid = [NSString stringWithFormat:@"%f%ld", [[NSDate date] timeIntervalSince1970], (long)randomId]; } //test - (IBAction)testPush:(id)sender { [self.navigationController pushViewController:[UIViewController new] animated:YES]; // [self presentViewController:[UIViewController new] animated:YES completion:nil]; } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } @end