> For the complete documentation index, see [llms.txt](https://help.tokenpocket.pro/developer-cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.tokenpocket.pro/developer-cn/mobile-wallet/mobile-sdk/ios.md).

# iOS

## SDK接入指南 <a href="#id-1" id="id-1"></a>

### 引入SDK

GitHub仓库: [**TP iOS SDK**](https://github.com/TP-Lab/Mobile-SDK/tree/master/iOS%20SDK)

下载仓库&#x4E2D;*`TPSDK.zip`*, 解压后，添加到工程目录。

1. 设&#x7F6E;*`URL scheme`*: *`Project`*->*`TARGETS`*->*`info`*->*`URL Types`*->添&#x52A0;*`URL scheme`*;
2. &#x5728;*`info.plist`*&#x4E2D;*`LSApplicationQueriesSchemes`*&#x4E0B;`添加`一项，值&#x4E3A;*`tpoutside`* ;

### 初始化 <a href="#id-2" id="id-2"></a>

* **在** *`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"
        ],
        ...,
    }
    */
}];
```

### 支持操作 <a href="#id-3" id="id-3"></a>

[#shou-quan-deng-lu](#shou-quan-deng-lu "mention")

[#qian-ming](#qian-ming "mention")

[#push-transaction](#push-transaction "mention")

### 代码示例 <a href="#id-4" id="id-4"></a>

#### **授权登录**

<pre><code>TPLoginObj *login = [TPLoginObj new];
login.dappName = @"xxx";
login.dappIcon = @"https:.../xx.png";
login.blockchains = @[
<strong>    [TPChainObj objWithNetwork:@"ethereum" chainId:@"1"],
</strong>    [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\"}"
}
</code></pre>

#### **签名**

```
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"
    },
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.tokenpocket.pro/developer-cn/mobile-wallet/mobile-sdk/ios.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
