PocketBuff拓展功能接入说明

1.接入须知

1.接入龙图iOSSDK的游戏及应用的iOS客户端开发者。
2.使用此文档内接口,需要先接入龙图iOSSDK(详情查看龙图iOSSDK文档,当前支持龙图官网最新版本)。
3.接入龙图iOSSDK后,需要配置GSWalletSDK需要的依赖库。

注:PocketBuff iOS终端SDK接入教程,只涉及SDK的使用方法。

1.0 开发要求


  • iOS 9.0 及以上版本

  • XCode 12 及以上版本

  • 1.1 申请你的AppID

    appid:必须参数,联系运营支持获取.

    1.2 下载SDK包和示例Demo

    在官网下载对应SDK和demo

    1.3 开发环境配置

    1、需要引入的三方库

    2、必须在 Xcode Build Settings 里面 Other Linker Flags 设置值 -ObjC。
    该项如果设置错误,运行时就会出现异常:unrecognized selector sent to instance exception

    3、添加URL TYPE
    在 Xcode 中,选择你的工程设置项,选中TARGETS一栏,在 Info 标签栏的 URL Types 中添加identifier为”gswallet” , URL Scheme 为 “gsw + 你所注册的应用程序 AppId”(如下图所示):

    如 AppId 为 1234567890,则 URL Scheme 设置为 gsw1234567890

    4、添加白名单

    1. <key>LSApplicationQueriesSchemes</key>
    2. <array>
    3. <string>com.pocketbuff.pbwallet</string>
    4. <string>pbwallet</string>
    5. </array>

    5、配置区块链登录识别参数(与Wemix共用同一配置)

    1. <key>LTBase_WemixLogin</key>
    2. <true/>

    如果使用PocketBuff请设置布尔值为true

    6、PocketBuff钱包debug日志控制配置
    如果打开PocketBuff钱包的debug日志(不同于龙图SDK,仅限于打开PocketBuff钱包日志)输出请设置布尔值为true

    1. <key>LTbase_GSWalletDebug</key>
    2. <true/>

    2 功能接入

    2.1 生命周期接口

    2.1.1 启动接口

    接口介绍

    1. /**
    2. * 启动接口
    3. */
    4. // 正式模式,与测试模式二选一,不能同时接入
    5. - (BOOL)LTGSWalletApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
    6. // 测试模式,与正式模式二选一,不能同时接入
    7. - (BOOL)LTGSWalletDebugTest:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

    示例

    1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    2. {
    3. // 正式模式,与测试模式二选一,不能同时接入
    4. [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application didFinishLaunchingWithOptions:launchOptions];
    5. // 测试模式,与正式模式二选一,不能同时接入
    6. [[LTGSWalletSDK sharedInstance] LTGSWalletDebugTest:application didFinishLaunchingWithOptions:launchOptions];
    7. }

    2.1.2 生命周期跳转接口

    1. /**
    2. * 生命周期跳转链接接口
    3. */
    4. - (BOOL)LTGSWalletApplication:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;
    5. - (BOOL)LTGSWalletApplication:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
    6. - (BOOL)LTGSWalletApplication:(UIApplication *)application handleOpenURL:(NSURL *)url;

    示例

    1. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
    2. {
    3. return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application handleOpenURL:url];
    4. }
    5. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
    6. sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    7. {
    8. return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    9. }
    10. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
    11. {
    12. return [[LTGSWalletSDK sharedInstance] LTGSWalletApplication:app openURL:url options:options];
    13. }

    2.2签名接口

    1. /// 签名接口
    2. /// @param viewController 当前控制器
    3. /// @param prepayId prepayId 通过服务器获取
    4. /// @param nonce nonce 通过服务器获取
    5. /// @param sign sign 通过服务器获取
    6. /// @param timestamp 时间戳 通过服务器获取
    7. - (void)LTGSWalletSendPayRequest:(UIViewController *)viewController prepayId:(NSString *)prepayId nonce:(NSString *)nonce sign:(NSString *)sign timestamp:(NSUInteger)timestamp;

    示例

    1. [[LTGSWalletSDK sharedInstance] LTGSWalletSendPayRequest:self prepayId:@"通过服务器获取" nonce:@"通过服务器获取" sign:@"通过服务器获取" timestamp:通过服务器获取];

    2.3签名回调代理

    代理方法

    1. 声明和设置代理
    2. @interface ViewController ()<LTGSWalletSDKDelegate>
    3. @end
    4. [LTGSWalletSDK sharedInstance].delegate = self;
    5. 实现代理
    6. - (void)LTGSWalletSDKSignInWithGSWalletCallBack:(NSDictionary *)dict code:(NSInteger)code result:(BOOL)result {
    7. /*
    8. 错误码:
    9. 100.成功
    10. 102.授权失败
    11. 103.签名失败
    12. 105.授权服务端查询请求失败(具体失败原因见服务端返回)
    13. 106.授权服务端绑定请求失败
    14. 107.用户取消首次绑定GS
    15. 108.用户取消三方绑定游客
    16. 110.用户三方绑定游客失败
    17. 111.点击关闭绑定页面
    18. 112.打开绑定页面失败
    19. 113.当前用户已经绑定了其他PocketBuff 账号
    20. 114.当前PocketBuff账号 ,已经被绑定
    21. */
    22. /*
    23. 失败格式
    24. dict :{
    25. error = "\U70b9\U51fb\U5173\U95ed\U7ed1\U5b9a\U9875\U9762";
    26. }
    27. 成功格式
    28. dict :{
    29. transactionId = "";
    30. customId = ;
    31. GSPay = "1";//此参数用来区分授权和签名,为空或!=1时是授权,=1时为签名
    32. }
    33. */
    34. NSLog(@"LTWeMixSDKSignInWithWemixCallBack dict :%@,code:%ld",dict,(long)code);
    35. if(result){
    36. [self showMessage:[NSString stringWithFormat:@"msg:成功;code:%ld",(long)code]];
    37. }else{
    38. [self showMessage:[NSString stringWithFormat:@"msg:%@;code:%ld",dict[@"error"],(long)code]];
    39. }
    40. }

    2.4 查询绑定状态接口

    接口介绍

    1. /// 查询绑定状态接口
    2. - (void)LTGSWalletSignInWithGSWalletCheckBind;

    示例说明

    1. //查询绑定
    2. [[LTGSWalletSDK sharedInstance] LTGSWalletSignInWithGSWalletCheckBind];

    2.5 绑定PocketBuff接口

    1. /// 绑定接口
    2. /// @param viewController 控制器
    3. - (void)LTGSWalletBindGSWallet:(UIViewController *)viewController;

    示例说明

    1. //绑定GSWallet
    2. [[LTGSWalletSDK sharedInstance] LTGSWalletBindGSWallet:UIViewController];

    2.6 查询绑定状态和绑定PocketBuff回调代理

    //代理回调

    1. //声明和设置代理(同之前代理设置,无需额外设置)
    2. @interface ViewController ()<LTGSWalletSDKDelegate>
    3. @end
    4. [LTGSWalletSDK sharedInstance].delegate = self;
    5. //实现代理
    6. /// 绑定状态/绑定结果
    7. /// @param type 回调类型 0=查询绑定状态回调;1=绑定GSWallet结果回调
    8. /// @param code code 1=请求成功,=其他为失败状态
    9. /// @param message 描述信息
    10. /// @param isBind 是否已绑定(type=0)/是否绑定成功(type=1);返回yes代表成功,accessToken,openId和tokenType,返回no则参数为空字符
    11. /// @param dict 返回参数accessToken/openId/tokenType
    12. - (void)LTGSWalletSDKSignFromGSWalletWithType:(NSString *)type code:(NSInteger)code message:(NSString *)message isBind:(BOOL)isBind dict:(NSDictionary *)dict {
    13. NSLog(@"LTGSWalletSDKSignFromGSWalletWithType type:%@ isBind:%@ code:%ld msg:%@ dict :%@,",type,isBind ? @"yes" : @"no",(long)code,message,dict);
    14. if ([type isEqualToString:@"0"]) {//查询
    15. if (code == 1) {
    16. if (isBind) {//已绑定
    17. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"yes" ,message,code]];
    18. }else{//未绑定
    19. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];
    20. }
    21. }else{//查询失败
    22. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];
    23. }
    24. }else{//单独绑定
    25. if (code == 1) {//绑定
    26. if (isBind) {//绑定成功
    27. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"yes" ,message,code]];
    28. }else{//绑定失败
    29. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];
    30. }
    31. }else{//绑定失败
    32. [self showMessage:[NSString stringWithFormat:@"type:%@ \nisBind:%@ \nmessage :%@ \ncode:%ld",type,@"no" ,message,code]];
    33. }
    34. }
    35. /*
    36. 错误码:
    37. 1.成功
    38. 102.授权失败
    39. 105.授权服务端查询请求失败(具体失败原因见服务端返回)
    40. 106.授权服务端绑定请求失败
    41. 107.用户取消首次绑定PocketBuff
    42. 108.用户取消三方绑定游客
    43. 110.用户三方绑定游客失败
    44. 111.点击关闭绑定页面
    45. 112.打开绑定页面失败
    46. 113.当前用户已经绑定了其他PocketBuff 账号
    47. 114.当前PocketBuff账号 ,已经被绑定
    48. */
    49. /*
    50. 失败格式
    51. dict :{//返回空字符
    52. accessToken = "";
    53. expire = 0;
    54. openId = "";
    55. tokenType = "";
    56. walletAddress = "";
    57. }
    58. 成功格式
    59. dict :{
    60. accessToken = 40959dbdf6654db7833efee42ec6428d;
    61. expire = 0;
    62. openId = 221112314949953;
    63. tokenType = "";
    64. walletAddress = 0x8A895C5239d9EBCC22eE58Da08A2d4C978e916fE;
    65. }
    66. */
    67. }

    返回字典格式说明

    参数 类型 说明
    walletAddress NSString 用户钱包地址 (1.0.2版本新增)
    accessToken NSString 如果绑定了才有值,返回绑定的PocketBuff用户token
    openId NSString 如果绑定了才有值,返回绑定的PocketBuff用户openid
    tokenType NSString 如果绑定了才有值,返回绑定的PocketBuff用户 Token 类型,bearer
    expire NSString accessToken 是否过期, 1 过期了, 0 没有过期。 如果token已经过期, 在签名的时候需要重新绑定失败的时候默认返回0

    2.7 打开网址

    发送在 GS 钱包 App 内置的浏览器中打开指定网页的请求

    1. /// 打开网址
    2. /// @param url 链接地址
    3. /// @param completion 回调
    4. - (void)LTGSWalletOpenWebViewRequest:(NSString *)url completion:(void (^ __nullable)(NSError *error))completion;

    示例说明

    1. [[LTGSWalletSDK sharedInstance] LTGSWalletOpenWebViewRequest:@"网址" completion:^(NSError *error) {
    2. if (error) {
    3. NSLog(@"GSWalletViewController LTGSModelOpenWebViewRequest 失败 %@",error.description);
    4. }
    5. }] ;

    2.8 检查钱包APP是否已被用户安装

    检查GS钱包APP是否已被用户安装

    1. BOOL isInstall = [[LTGSWalletSDK sharedInstance] LTGSWalletIsAppInstalled];

    2.9 返回app下载地址

    返回app下载地址

    1. NSString *appUrl = [[LTGSWalletSDK sharedInstance] LTGSWalletGetAppInstallURL];

    3. 错误码

    状态码 说明
    1 成功(查询绑定状态和绑定PocketBuff回调)
    100 成功(授权回调)
    102 授权失败
    103 签名失败
    105 授权服务端查询请求失败(具体失败原因见服务端返回)
    106 授权服务端绑定请求失败
    107 用户取消首次绑定PocketBuff
    108 用户取消三方绑定游客
    110 用户三方绑定游客失败
    111 点击关闭绑定页面
    112 打开绑定页面失败
    113 当前用户已经绑定了其他PocketBuff 账号
    114 当前PocketBuff账号 ,已经被绑定