Now, you build an iOS application that can access and run your Blockstack web
Now, you build an iOS application that can work with your Blockstack web
application on a mobile device.
application on a mobile device.
### Create an XCode Project
### Create an XCode Project
This tutorial uses XCode 9.3, you can use another version but be aware that some
This tutorial uses XCode 11.1, you can use another version but be aware that some
menu items and therefore these procedures may be differœent on your version.
menu items and therefore these procedures may be differœent on your version.
1. Launch the XCode interface.
1. Launch the XCode interface.
@ -267,7 +268,22 @@ menu items and therefore these procedures may be differœent on your version.
![](images/single-view-app.png)
![](images/single-view-app.png)
5. **Choose options for your new project** for your project.
5. On the **Choose options for your new project** dialog, set the following:
<tableclass="uk-table uk-table-small">
<tr>
<th>Product Name</th>
<td><code>hello-blockstack-ios</code></td>
</tr>
<tr>
<th>Organization Name</th>
<td><code><i>USERNAME</i></code></td>
</tr>
<tr>
<th>User Interface</th>
<td>Storyboard</td>
</tr>
</table>
![](images/choose-new-options.png)
![](images/choose-new-options.png)
@ -275,9 +291,7 @@ menu items and therefore these procedures may be differœent on your version.
The system prompts you for a location to store your code.
The system prompts you for a location to store your code.
7. Save your project in your `hello-blockstack` directory.
7. Save your project in your `hello-blockstack-ios` directory.
When you are done, you will have a `hello-blockstack/hello-blockstack-ios` subdirectory.
8. Close XCode.
8. Close XCode.
@ -290,7 +304,7 @@ Create a target section by writing target `$TARGET_NAME do` and an `end` a few
lines after.
lines after.
1. Open a terminal window on your workstation.
1. Open a terminal window on your workstation.
2. Navigate to and change directory into the root of your project directory.
2. Change directory into your new project directory where your `hello-blockstack-ios.xcodeproj` file was created.
```swift
```swift
$ cd hello-blockstack-ios
$ cd hello-blockstack-ios
@ -328,15 +342,15 @@ lines after.
### Install Blockstack SDK and open the pod project
### Install Blockstack SDK and open the pod project
1. Close your new XCode project.
1. Close your new XCode project if you haven't already.
2. Change to the root of your `hello-blockstack-ios` project.
2. In terminal, make sure it is open to the root of your `hello-blockstack-ios` project.
3. Initialize the project with Cocoapods.
3. Initialize the project with Cocoapods via the `pod install` command.
```bash
```bash
$ pod install
$ pod install
Analyzing dependencies
Analyzing dependencies
Downloading dependencies
Downloading dependencies
Installing Blockstack (0.7.2)
Installing Blockstack (1.0.1)
Installing CryptoSwift (0.15.0)
Installing CryptoSwift (0.15.0)
Installing PromisesObjC (1.2.8)
Installing PromisesObjC (1.2.8)
Installing PromisesSwift (1.2.8)
Installing PromisesSwift (1.2.8)
@ -370,13 +384,13 @@ lines after.
project title. If you see the warning, continue to step 7. Otherwise, go to the next section.
project title. If you see the warning, continue to step 7. Otherwise, go to the next section.
7. Click the signal to reveal the warning.
7. Click the signal to reveal the warning.
8. Click **Update to recommended settings**.
8. Click **Next**.
![](images/indicator.png)
![](images/indicator.png)
9. Choose **Perform Changes** and **Continue** when prompted.
9. Select all the targets and press **Next** and **Continue** when prompted.
The indicator disappears.
Make sure you have no errors; warnings are acceptable to continue.
### Choose a custom protocol handler
### Choose a custom protocol handler
@ -386,14 +400,14 @@ the user back to your iOS app. In this example, you use `myblockstackapp://`.
1. Open the `.xcworkspace` file in XCode if it isn't open already.
1. Open the `.xcworkspace` file in XCode if it isn't open already.
2. Select the top node of your project.
2. Select the top node of your project.
1. Select the **Info** tab in XCode.
3. Select the **Info** tab in XCode.
2. Scroll to **URL Types** and press **+** (plus) sign.
4. Scroll to **URL Types** and press **+** (plus) sign.
3. Enter an **Identifier** and **URL Schemes** value.
5. Enter an **Identifier** and **URL Schemes** value.
| **Identifier** | `MyBlockstackApp` |
| **Identifier** | `MyBlockstackApp` |
| **URL Schemes** | `myblockstackapp` |
| **URL Schemes** | `myblockstackapp` |
4. Set the **Role** to **Editor**.
6. Set the **Role** to **Editor**.
When you are done the **URL Types** appears as follows:
When you are done the **URL Types** appears as follows:
@ -479,14 +493,14 @@ All iOS applications require a splash page.
### Update the Main.storyboard
### Update the Main.storyboard
Rather than have you build up your own UI, this section has you copy and paste a layout into the XML file source code for the **Main.storyboard** file.
Rather than have you build up your own UI in the interface builder, this section has you copy and paste a layout into the XML file source code for the **Main.storyboard** file.
1. Select the `Main.storyboard` file.
1. Select the `Main.storyboard` file.
2. Choose **Open As > Source Code**
2. Choose **Open As > Source Code**
The `blockstack-example/blockstack-example/Base.lproj/Main.storyboard` file
The `hello-blockstack-ios/Base.lproj/Main.storyboard` file
defines the graphical elements. Some elements are required before you can
defines the graphical elements, and their functionality will be defined in
functionality to your code.
a respective `.swift` file.
3. Within the `<viewController>` element, replace the existing `<view>` subelement with the following:
3. Within the `<viewController>` element, replace the existing `<view>` subelement with the following:
@ -532,6 +546,14 @@ Rather than have you build up your own UI, this section has you copy and paste a
<viewLayoutGuidekey="safeArea"id="6Tk-OE-BBY"/>
<viewLayoutGuidekey="safeArea"id="6Tk-OE-BBY"/>
</view>
</view>
```
```
4. Select the Main.storyboard and choose **Open as > Interface Builder - Storyboard**.
![](images/main-storyboard.png)
You should see the following:
![](images/new-storyboard.png)
### Add the UI variables to the ViewController file.
### Add the UI variables to the ViewController file.
@ -539,27 +561,44 @@ In this section, you edit the `ViewController.swift` file using the storyboard a
1. Select the **Main.storyboard** and choose **Open As > Interface Builder - storyboard**.
1. Select the **Main.storyboard** and choose **Open As > Interface Builder - storyboard**.
![](images/main-storyboard.png)
2. With the interface builder open, choose **Editor > Assistant** to edit the `ViewController.swift` file.
2. With the interface builder open, display the `ViewController.swift` file in the right panel.
![](images/view-editors.gif)
![](images/view-editors.png)
4. In the storyboard, select the **Sign into Blockstack** button.
3. In the storyboard, select the **Sign into Blockstack** button.
5. Control-drag from the button to the code display in the editor on the right, stopping the drag at the line below controller's opening statement.
4. Control-drag from the button to the code display in the editor on the right, stopping the drag at the line below controller's `viewDidLoad()` statement.
![](images/add-action.gif)
![](images/add-action.gif)
6. Repeat this process with the storyboard's purple **hello-blockstack-ios** label.
5. Set the **Connection** to `Outlet`.
6. Name the new section `signinButton`.
![](images/signinbutton.png)
7. Press **Connect**.
8. Repeat with purple **hello-blockstack-ios** label, name it `nameLabel.
When you are done, your 'ViewController' file contains the following variables:
9. Add an import statement for the `Blockstack` and another for the `SafariServices` module.
When you are done, your `ViewController.swift` file contains the following:
```swift
```swift
import UIKit
import Blockstack
import SafariServices
class ViewController: UIViewController {
class ViewController: UIViewController {
@IBOutlet var nameLabel: UILabel!
override func viewDidLoad() {
@IBOutlet var signInButton: UIButton!
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet var signinButton: UIButton!
}
```
```
And XCode has added two outlines to the `Main.storyboard` source.
And XCode has added two outlines to the `Main.storyboard` source.
@ -567,7 +606,7 @@ In this section, you edit the `ViewController.swift` file using the storyboard a