查看并运行 MKSDKDemo/MKSDKDemo.xcodeproj
-
将 Frameworks 内的MKSDK.framework和MKSDK.xcassets添加(拖放)到你的工程目录中。
-
在对应项目Targets下找到General。
在Deployment Info根据游戏需要,自行限制横屏还是竖屏。并且在AppDelegate入口限制方向- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait; }
勾选 Hide status bar 和requires full screen,并且在info.plist下加View controller-based status bar appearance 设置为NO 并且在Embedded Binaries和Linked Frameworks and Libraries链接 frameworks:
-
导入
<MKSDK/MKSDK.h>
。
#import <MKSDK/MKSDK.h>
- 初始化SDK。并更改对应的参数
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[MKSDK sharedXSSDK] mkInitWithSDKParameters:1 subGameId:1 secretKey:@"4f76c696869efaa7f84afe5a2d0de332"
gameKey:@"459922aa8968c4a664a988df9749bcba" trackKey:@"c497a2997779e09ce454701e01b81a15" ryChannelID:@"unknown"
success:^{
} failure:^(int errcode, NSString *errorMessage) {
}];
return YES;
}
[[MKSDK sharedXSSDK] mkSDKVersion];
- (void)loginButtonClick
{
[[MKSDK sharedXSSDK] mkLogin];
}
- (void)payButtonClick
{
MKOrder *order = [MKOrder new];
[order setServerId:@"serverId1"];
[order setTotalFee:1];
[order setRoleId:@"9527"];
[order setRoleName:@"凯特琳"];
[order setProductName:@"未来战士"];
[order setProductDescription:@"凯特琳皮肤"];
[order setCoOrderId:[self getOrderStringByTime]];
[order setCustomInfo:@"好戏开场了,想看帽子戏法吗"];
[order setProductId:@"com.mk.mksdkdemo.1"];
[[MKSDK sharedXSSDK] mkPay:order];
}
[[MKSDK sharedXSSDK] setLoginSuccessBlock:^(MKUser *user) {
NSString *userId = user.userId;
NSString *userName = user.username;
NSString *accessToken = user.accessToken;
NSLog(@"userId -- %@", userId);
NSLog(@"userName -- %@", userName);
NSLog(@"accessToken -- %@", accessToken);
if (loginSuccessSource == MKLoginSuccessByLogin) {
NSLog(@"登陆来源");
}
else if (loginSuccessSource == MKLoginSuccessByRegister)
{
NSLog(@"注册来源");
}
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
NSString *dateTime = [formatter stringFromDate:date];
MKRole *role = [MKRole new];
[role setServerId:@"serverId1"];
[role setServerName:@"紫陌红尘"];
[role setRoleId:@"9527"];
[role setRoleName:@"凯特琳"];
[role setRoleLevel:1];
[role setLoginTime:dateTime];
[[MKSDK sharedXSSDK] mkReportRole:role];
}];
[[MKSDK sharedXSSDK] setLogoutBlock:^{
NSLog(@"注销事件的回调");
}];
[[MKSDK sharedXSSDK] setPayViewCloseBlock:^{
NSLog(@"支付页面关闭的回调");
}];
[[MKSDK sharedXSSDK] setCreateOrderBlock:^(MKPayCode payCode) {
NSLog(@"IAP支付回调 - %ld", payCode);
}];
1、项目编译build Settings 的Base SDK选当前最新的版本。至少iOS11以上。不然会出现一些比较奇怪的问题。
该项目最低支持 iOS 8.0
和 Xcode 7.0
。
MKSDK 使用 MIT 许可证,详情见 LICENSE 文件。