> For the complete documentation index, see [llms.txt](https://help.tokenpocket.pro/developer-en/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-en/wallet/mobile-sdk/ios.md).

# iOS

## SDK **Integration** Guide

### Import SDK

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

Download the *`TPSDK.zip`* in the [***GitHub repository***](https://github.com/TP-Lab/Mobile-SDK/tree/master/iOS%20SDK). Unzip *`TPSDK.zip`* and add it into your Xcode project;

1. Set your *URL scheme*: *`Project`*->*`TARGETS`*->*`info`*->*`URL Types`*->*`Add URL scheme`*;
2. Add an item *`LSApplicationQueriesSchemes`* in the *`info.plist`*，value with *`tpoutside`;*

### **Initializing**

* **Add related .h file in** *`AppDelegate.m`*

```
#import <TPSDK/TPSDK.h>
```

* **Register your app&#x20;*****scheme*****&#x20;in method** *`application:didFinishLaunchingWithOptions:`*

```
[TPApi registerAppID:@"demoapp"];
```

* **Handle&#x20;*****callback*****&#x20;in method** *`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",       // When success
        "publickey" : "xxx...xxx",    // When success
        "permissions" : [             // When success; for eosio/iost networks.
            "active",
            "owner"
        ],
        ...,
    }
    */
}];
```

### Supported Operations

[#login](#login "mention")

[#sign](#sign "mention")

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

### Demo

#### **Login Authorization**

```
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];


/// Response ↓
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\"}"
}
```

#### Sign

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


/// Response ↓
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"] /** If selected BSC */
];
transaction.actions = @{
    @"from": @"0x...",
    @"to": @"0x...",
    @"data": @"0x095ea7b30000000000000000000000004184d9a175d13e568f3466ea93c02b6f8eb9f8c10000000000000000000000000000000000000000000000000000000000000000",
    @"value": @"0x0",
    @"gasPrice": @"0x16b969d000",
    @"gas": @"0x186a0",
    @"nonce": @"0x01"
};
[TPApi sendObj:transaction];


/// Response ↓
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];


/// Response ↓
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];


/// Response ↓
TPRespObj.data
{
    ...,
    "txId" : "abc...123",
    "data" : {
        "address":"xxx",
        "decryptedData":"xxx"
    },
}
```
