8.2 iOS-SDK

CocosSDK 集成使用文档

Example

要运行示例项目,请克隆repo,然后首先从示例目录运行’pod install’。

依赖库

AFNetworking
FMDB
Secp256k1_A
SocketRocket

安装

1.使用 CocoaPods 集成安装

pod 'CocosSDK'

2.手动集成

添加 CocosSDK 目录下 Class 文件夹所有文件。
添加依赖库到项目中。

基础功能

初始化
1.说明和用途
初始化 SDK 基础,连接节点、配置 ChainId 和链标识

2.接口函数

/**
  Initialize SDK
  @param url RPC     Node
  @param faucetUrl   URL Address
  @param timeOut     Timeout
  @param coreAsset   Chain identifier
  @param chainId     Chain ID
  @param connectedStatus Status of connection
  */
 - (void)Cocos_ConnectWithNodeUrl:(NSString *)url
         Fauceturl:(NSString *)faucetUrl
            TimeOut:(NSTimeInterval)timeOut
         CoreAsset:(NSString *)coreAsset
            ChainId:(NSString *)chainId
     ConnectedStatus:(void (^)(WebsocketConnectStatus     connectStatus))connectedStatus;

3.示例代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 // 测试节点
 [[CocosSDK shareInstance] Cocos_ConnectWithNodeUrl:@"ws://39.106.126.54:8050" Fauceturl:@"http://47.93.62.96:3000" TimeOut:2 CoreAsset:@"COCOS" ChainId:@"53b98adf376459cc29e5672075ed0c0b1672ea7dce42b0b1fe5e021c02bda640" ConnectedStatus:^(WebsocketConnectStatus connectStatus) {
 }];
 return YES;
}

设置日志输出

1.说明和用途
设置是否在console输出sdk的log信息
2.接口函数

/**
  *  Open debug log
  *
  *  @param isOpen YES means open,No means close
  */
 - (void)Cocos_OpenLog:(BOOL)isOpen;

创建账户

说明和用途
钱包模式
钱包模式创建账户,钱包模式创建的账户不能用账户名密码登录
账户模式
账户模式创建账户,钱包模式创建的账户可以用账户名密码登录
1.接口函数

/**
  Create account

  @param walletMode  Mode of wallet
  @param accountName Account
  @param password    Password
  @param autoLogin   Auto log in
  */
 - (void)Cocos_CreateAccountWalletMode:(CocosWalletMode)walletMode
      AccountName:(NSString *)accountName
         Password:(NSString *)password
        AutoLogin:(BOOL)autoLogin
          Success:(SuccessBlock)successBlock
            Error:(Error)errorBlock;

删除/退出钱包

1.使用说明
清除 SDK 保存的登录和导入记录

2.接口函数

/**
  Delete wallet
  @param accountName Account
  */
 - (void)Cocos_DeleteWalletAccountName:(NSString *)accountName
           Success:(SuccessBlock)successBlock
             Error:(Error)errorBlock;

登录钱包

1.使用说明
账户模式下,使用账户名和密码登录钱包

2.接口函数

/**
  Log in by account

  @param accountName Account
  @param password    Password
  */
 - (void)Cocos_LoginAccountWithName:(NSString *)accountName
           Password:(NSString *)password
             Success:(SuccessBlock)successBlock
               Error:(Error)errorBlock;

转账

1.使用说明
转账

2.接口函数

/**
  Transfer

  @param fromName        Sender's account
  @param toName          Receiver's account
  @param password        Password
  @param transferAsset   Asset's name(eg. COCOS)
  @param assetAmount     assetAmount Transfer amount
  @param feePayingAsset  Charge's currency(require)
  @param memo            Memo String
  */
 - (void)Cocos_TransferFromAccount:(NSString *)fromName
               ToAccount:(NSString *)toName
                Password:(NSString *)password
           TransferAsset:(NSString *)transferAsset
             AssetAmount:(NSString *)assetAmount
          FeePayingAsset:(NSString *)feePayingAsset
                    Memo:(NSString *)memo
               Success:(SuccessBlock)successBlock
                 Error:(Error)errorBlock;

状态码

状态码说明

codemessage说明
300Chain sync error, please check your system clock链同步错误,请检查您的系统时钟
301RPC connection failed. Please check your network连接RPC失败,请检查你的网络
1操作成功
0failed操作失败,返回错误状态描述不固定,可直接提示res.message或统一提示为操作失败
101Parameter is missing参数缺失
1011Parameter error参数错误
102The network is busy, please check your network connection网络繁忙,请检查你的网络连
103Please enter the correct account name(/^a-z{4,63}/$)请输入正确的账户名(正则/^a-z{4,63}/$)
104XX not foundXX 不存在
105wrong password密码错误
106The account is already unlocked账户已经处于解锁状态
107Please import the private key请先导入私钥
108User name or password error (please confirm that your account is registered in account mode, and the account registered in wallet mode cannot be logged in using account mode)用户名或密码错误(请确认你的账户是通过账户模式注册的,钱包模式注册的账户不能使用账户模式登录)
109Please enter the correct private key请输入正确的私钥
110The private key has no account information该私钥没有对应的账户信息
111Please login first请先登录
112Must have owner permission to change the password, please confirm that you imported the ownerPrivateKey必须拥有owner权限才可以进行密码修改,请确认你导入的是ownerPrivateKey
113Please enter the correct original/temporary password请输入正确的原始密码/临时密码
114Account is locked or not logged in帐户被锁定或未登录
115There is no asset XX on block chain区块链上不存在资产 XX
116Account receivable does not exist收款方账户不存在
117The current asset precision is configured as X ,and the decimal cannot exceed X当前资产精度配置为 X ,小数点不能超过 X
118Encrypt memo failed备注加密失败
119Expiry of the transaction交易过期
120Error fetching account record获取帐户记录错误
121block and transaction information cannot be found查询不到相关区块及交易信息
122Parameter blockOrTXID is incorrect参数blockOrTXID不正确
123Parameter account can not be empty参数account不能为空
124Receivables account name can not be empty收款方账户名不能为空
125Users do not own XX assets用户未拥有 XX 资产
127No reward available没有可领取的奖励
129Parameter ‘memo’ can not be empty memo不能为空
130Please enter the correct contract name(/^a-z{4,63}$/)请输入正确的合约名称(正则/^a-z{4,63}$/)
131Parameter ‘worldView’ can not be empty世界观名称不能为空
133Parameter ‘toAccount’ can not be empty toAccount不能为空
135Please check parameter data type请检查参数数据类型
136Parameter ‘orderId’ can not be emptyorderId不能为空
137Parameter ‘NHAssetHashOrIds’ can not be emptyNHAssetHashOrIds不能为空
138Parameter ‘url’ can not be empty接入点地址不能为空
139Node address must start with ws:// or wss://节点地址必须以 ws:// 或 wss:// 开头
140API server node address already existsAPI服务器节点地址已经存在
141Please check the data in parameter NHAssets请检查参数NHAssets中的数据
142Please check the data type of parameter NHAssets请检查参数NHAssets的数据类型
144Your current batch creation / deletion / transfer number is X , and batch operations can not exceed X您当前批量 创建/删除/转移 NH资产数量为 X ,批量操作数量不能超过 X
145XX contract not foundXX 合约不存在
146The account does not contain information about the contract账户没有该合约相关的信息
147NHAsset do not exist非同质资产不存在
148Request timeout, please try to unlock the account or login the account请求超时,请尝试解锁账户或登录账户
149This wallet has already been imported此私钥已导入过钱包
150Key import error导入私钥失败
151File saving is not supported您的浏览器不支持文件保存
152Invalid backup to download conversion无效的备份下载转换
153Please unlock your wallet first请先解锁钱包
154Please restore your wallet first请先恢复你的钱包
155Your browser may not support wallet file recovery浏览器不支持钱包文件恢复
156The wallet has been imported. Do not repeat import该钱包已经导入,请勿重复导入
157Can’t delete wallet, does not exist in index请求超时,请尝试解锁账户或登录账户
158Imported Wallet core assets can not be XX , and it should be XX导入的钱包核心资产不能为 XX ,应为 XX
159Account exists账户已存在
160You are not the creator of the Asset XX .你不是该资产的创建者
161Orders do not exist订单不存在
162The asset already exists资产已存在
163The wallet already exists. Please try importing the private key钱包已经存在,请尝试导入私钥
164worldViews do not exist世界观不存在
165There is no wallet account information on the chain链上没有该钱包账户信息
166The Wallet Chain ID does not match the current chain configuration information. The chain ID of the wallet is: XX该钱包链id与当前链配置信息不
167The current contract version ID was not found当前合约版本id没有找到 X
168This subscription does not exist当前没有订阅此项
169Method does not existAPI方法不存在

合作项目

CocosBCXWallet

开源地址

iOSSDK

Updated 8 months ago


8.2 iOS-SDK


CocosSDK 集成使用文档

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.