一、SDK集成

1.1.1 info.plist配置

  • App Transport Security Settings -> Allow Arbitrary Loads:YES

1.1.2 Pod依赖

source 'https://gitee.com/mobad/Specs.git' # 自建仓库,须放在 CocoaPods 前面
source 'https://github.com/CocoaPods/Specs.git'

# platform :ios, '9.0'
target 'podTest' do
  # use_frameworks!
  pod 'AFNetworking'
  pod 'MJExtension'
  pod 'ReactiveObjC'
  pod 'MobGameSDK', '~> 2.0.4'
  # Pods for podTest
end

二、初始化

#import <MobGameSDK/MobGameSDK.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 2.初始化视频SDK
    MobGameConfigModel *config =[[MobGameConfigModel alloc] init];
    // 渠道标示(必填)
    config.appId = @"ba0063bfbc1a5ad878";
    // 接入方App用户id
    config.userId = @"userId";
    
    if ([MobGameSDKApi setupWithConfig:config]{
        NSLog(@"MobGameSDK setup success");
    }
    return YES;
}

三、游戏接入

3.1.1 调用接口

/**
 * 获取游戏ViewController
 * @return h5游戏ViewController
 */
+ (UIViewController *)h5GameViewController;

/**
 * 获取游戏ViewController
 * @return APP游戏ViewController
 */
+ (UIViewController *)appGameViewController;

/**
 * 登录
 */
+ (void)login:(NSString *)userId;

/**
 * 退出登录
 */
+ (void)logout;

3.2 示例代码

#import <MobGameSDK/MobGameSDK.h>

- (IBAction)appGameClicked:(id)sender {
    UIViewController *vc = [MobGameSDKApi appGameViewController];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)h5GameClicked:(id)sender {
    UIViewController *vc = [MobGameSDKApi h5GameViewController];
    [self.navigationController pushViewController:vc animated:YES];
}