iOS

SDK接入指南

引入SDK

GitHub仓库: TP iOS SDK

下载仓库中TPSDK.zip, 解压后,添加到工程目录。

  1. 设置URL scheme: Project->TARGETS->info->URL Types->添加URL scheme;

  2. info.plistLSApplicationQueriesSchemes添加一项,值为tpoutside ;

初始化

  • AppDelegate.m 中添加头文件

#import <TPSDK/TPSDK.h>
  • application:didFinishLaunchingWithOptions: 方法中注册scheme

[TPApi registerAppID:@"demoapp"];
  • application:openURL: 方法中添加监听回调方法

[TPApi handleURL:url options:options result:^(TPRespObj *respObj) {
    respObj.result;     // TPRespResultCanceled = 0,TPRespResultSuccess, TPRespResultFailure,
    respObj.message;    // Result message
    respObj.data;       // Json details
    /* Json details:
    {
        "result" : 1,
        "action" : "sign",
        "version" : "1.0",
        "protocol" : "TPProtocol",
        "ref" : "TokenPocket",
        "wallet" : "xxx...xxx",       // 成功时返回
        "publickey" : "xxx...xxx",    // 成功时返回
        "permissions" : [             // 成功时返回;  eosio/iost网络返回该字段
            "active",
            "owner"
        ],
        ...,
    }
    */
}];

支持操作

授权登录

签名

Push Transaction

代码示例

授权登录

TPLoginObj *login = [TPLoginObj new];
login.dappName = @"xxx";
login.dappIcon = @"https:.../xx.png";
login.blockchains = @[
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"1"],
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"56"], /** BSC */
];
[TPApi sendObj:login];


/// 回调数据 ↓
TPRespObj.data
{
    ...,
    "ref" : "TokenPocket",
    "wallet" : "0x...",
    "sign" : "...",
    "network" : "ethereum",
    "chainId" : "56",
    "timestamp" : "1554266633",
    "sign" : "{\"r\":\"0x3a5...bd5\",\"message\":\"1554266633{account}TokenPocket\",\"messageHash\":\"0xcdf...f29\",\"s\":\"0x6c1...f55\",\"signature\":\"0x3a5...51b\",\"v\":\"0x1b\"}"
}

签名

TPSignObj *sign = [TPSignObj new];
sign.dappName = @"xxx";
sign.dappIcon = @"https:.../xx.png";
sign.message = @"sign data...";
sign.blockchains = @[
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"56"], /** 如果选择 BSC */
];
[TPApi sendObj:sign];


/// 回调数据 ↓
TPRespObj.data
{
    ...,
    "sign" : "signature...",
}

Push Transaction

TPPushTransactionObj *transaction = [TPPushTransactionObj new];
transaction.dappName = @"xxx";
transaction.dappIcon = @"https:.../xx.png";
transaction.blockchains = @[
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"56"], /** 如果选择 BSC */
];
transaction.actions = @{
    @"from": @"0x...",
    @"to": @"0x...",
    @"data": @"0x095ea7b30000000000000000000000004184d9a175d13e568f3466ea93c02b6f8eb9f8c10000000000000000000000000000000000000000000000000000000000000000",
    @"value": @"0x0",
    @"gasPrice": @"0x16b969d000",
    @"gas": @"0x186a0",
    @"nonce": @"0x01"
};
[TPApi sendObj:transaction];


/// 回调数据 ↓
TPRespObj.data
{
    ...,
    "txId" : "abc...123",
    "processed" : {
        ...
    },
}

EthGetEncryptionPublicKey

TPEthGetEncryptionPublicKeyObj *ethGetEncryptionPublicKeyObj = [TPEthGetEncryptionPublicKeyObj new];
ethGetEncryptionPublicKeyObj.dappName = @"xxx";
ethGetEncryptionPublicKeyObj.dappIcon = @"https:.../xx.png";
ethGetEncryptionPublicKeyObj.blockchains = @[
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"56"], /** 如果选择 BSC */
];
TPEthGetEncryptionPublicKeyObjData *data = TPEthGetEncryptionPublicKeyObjData.new;
data.address = @"xxx";
ethGetEncryptionPublicKeyObj.data = data;
[TPApi sendObj:ethGetEncryptionPublicKeyObj];


/// 回调数据 ↓
TPRespObj.data
{
    ...,
    "txId" : "abc...123",
    "data" : {
        "address":"xxx",
        "encryptitonPublicKey":"xxx"
    },
}

EthDecrypt

TPEthDecryptObj *ethDecryptObj = [TPEthDecryptObj new];
ethDecryptObj.dappName = @"xxx";
ethDecryptObj.dappIcon = @"https:.../xx.png";
ethDecryptObj.blockchains = @[
    [TPChainObj objWithNetwork:@"ethereum" chainId:@"56"], /** 如果选择 BSC */
];
TPEthDecryptObjData *data = TPEthDecryptObjData.new;
data.address = @"xxx";
data.message = @"xxxxxxx";
ethDecryptObj.data = data;
[TPApi sendObj:ethDecryptObj];


/// 回调数据 ↓
TPRespObj.data
{
    ...,
    "txId" : "abc...123",
    "data" : {
        "address":"xxx",
        "decryptedData":"xxx"
    },
}

Last updated