![](https://box.kancloud.cn/f200f9c1ee24d50ed84c30c85113c81d_163x47.jpeg)
****
# WoGameSDK接入指南(iOS)
> 注:本文为iOS终端WoGameSDK的新手使用教程,只涉及教授SDK的使用方法,默认读者已经熟悉Xcode开发工具的基本使用方法,以及具有一定的编程知识基础等。
## 1. 使用步骤
> SDK支持iOS 9.0及以上操作系统,支持armv7、arm64处理器。
### 1.1 集成
#### 1.1.1 添加SDK依赖包
```js
WoGameSDK.framework
//强烈建议使用SDK附带的Bugly
Bugly.framework
```
#### 1.1.2 添加系统依赖包
```js
JavaScriptCore.framework
```
#### 1.1.3 build setting设置
```js
other Linker Flags 添加 `-ObjC`
Enable Bitcode 设置 NO
```
#### 1.1.4 添加Schem
```ll
1. 在工程的info.plist文件中添加 LSApplicationQueriesSchemes
2. 在LSApplicationQueriesSchemes下添加item `weixin`
3. 在LSApplicationQueriesSchemes下添加item `alipay`
```
#### 1.1.5 在代码中要使用到DK的地方引入头文件
```c
#import <WoGameSDK/WoGameSDK.h>
```
## 2.接口API说明
### 2.1 (必接*)登录/登出
```c
//WoGameApi.h
//(*必接)Session失效通知,建议在收到通知时退出游戏到登录界面
UIKIT_EXTERN NSNotificationName const kWoSessionExpiredNotification;
//eg: 在合适的地方注册通知
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(sessionExpired:)
name:kWoSessionExpiredNotification
object:nil];
- (void)sessionExpired:(NSNotification *)noti{
//从其它界面退回来的
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES completion:NULL];
return;
}
}
#############################################
/////////////////////////////////////////////
//(*必接)登录
// completion: 登录回调
+ (void)login:(void(^)(NSDictionary *userInfo,NSError *error))completion;
//eg: 在合适的地方调用
[WoGameApi login:^(NSDictionary *userInfo, NSError *error) {
if(!error){
//登录成功
NSString *token = userInfo[@"token"];
NSString *userId = userInfo[@"uid"];
NSLog(@"登录成功 token = (%@), userId = (%@)",token,userId);
}else{
//登录失败
[ProgressHUD show:error.localizedDescription];
}
}];
#############################################
/////////////////////////////////////////////
//(*必接)退出
// completion: 注销回调
+ (void)logout:(void(^)(void))completion;
//eg: 在合适的地方调用
[WoGameApi logout:^{
[self dismissViewControllerAnimated:YES completion:NULL];
}];
#############################################
/////////////////////////////////////////////
//切换账号
+ (void)switchAccount;
//eg: 在合适的地方调用
[WoGameApi switchAccount];
```
### 2.2 (必接*)品牌大图
展示WoGame品牌大图,2秒后会自动消失,如果未接入,以下所有功能都将失效,此功能请确保在程序第一个界面出来前调用
```c
//WoGameApi.h
//展示WoGame品牌大图
+ (void)showWoGameBranchPage;
//eg: 在合适的地方调用
[WoGameApi showWoGameBranchPage];
```
### 2.3 (*必接)支付
在调用支付时,请确保完成了3.1的接入。
由于为了规避AppStore的一些审核机制,此API使用了`xxx`这样的命名
```c
//AppDelegate.m
//唤醒第三方支付
+ (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url;
//eg: 在AppDelegate下面的生命周期方法内中调用
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary *)options{
return [WoGameApi application:app
openURL:url];
}
//WoGameApi.h
//支付:网页支付和微信支付没有回调
// data: 数据模型,WoProductData类实例对象
// completion: 完成回调(wap 支付时没有回调)
+ (void)xxx:(WoProductData *)data
completion:(void(^)(NSDictionary *userInfo,NSError *error))completion;
//eg: 在合适的地方调用
WoProductData *data = [WoProductData new];
data.orderID = @"19010112121267891";
data.productDesc = @"充值100元宝,赠送20元宝";
data.price = @"66.00";
data.notifyUrl = @"schem://ip:port/paymentCallback";
data.roleId = @"001";
data.roleName = @"GM_001";
data.serverName = @"1服-混服";
data.productId = @"苹果内购商品ID";
data.extension = @"自定义数据信息,原样返回给你们服务端";
data.notifyUrl = @"ip:port/paymentCallback";
data.extension = @"自定义数据信息,原样返回给你们服务端";
[WoGameApi xxx:data completion:^(NSDictionary *userInfo, NSError *error) {
if (!error) {
//登录失败
[ProgressHUD show:@"支付成功"];
}else{
//登录失败
[ProgressHUD show:error.localizedDescription];
}
}];
```
_ _ _
至此,你已经能使用WoGameSDK的API内容了。如果想更详细了解每个API的用法,请阅读[SDK Demo](#) 源码。