iOS クイックスタート

In this guide, we will get you up and running quickly with a sample application you can build on as you learn more about Programmable Chat. Sound like a plan? Then let's get cracking!

目次

アカウント情報の収集

The first thing we need to do is grab all the necessary configuration values from our Twilio account. To set up our back-end for Chat, we will need five pieces of information:

設定値 説明
サービスインスタンスSID Chatデータ用のデータベースのようなもので、コンソールから生成できます
Account SID プライマリ Twilio アカウント識別子 - 調べるにはコンソールのここにアクセスします。
API Key 認証に使用します。ここで生成します。
API Secret 認証に使用します。上記と同じようにここで生成します。
Mobile Push Credential SID Used to send notifications from Chat to your app - create one in the console here or learn more about Chat Push Notifications in iOS.

Create a Twilio Function

When you build your application with Twilio Chat, you will need two pieces - the client (this iOS app) and a server that returns access tokens. If you don't want to set up your own server, you can use Twilio Functions to easily create this part of your solution.

If you haven't used Twilio Functions before, it's pretty easy - Functions are a way to run your Node.js code in Twilio's environment. You can create new functions on the Twilio Console's Manage Functions Page.

You will need to choose the "Programmable Chat Access Token" template:

Twilio Functions Chat Access Token Template

Select the Programmable Chat Token template and click Create on the above dialog box, and then fill in the account information you gathered above on the next screen.

Chat Access Token Function Credentials

After you do that, the Function will appear, and you can read through it. Save it, and it will immediately be published at the URL provided - go ahead and put that URL into a web browser, and you should see a token being returned from your Function. If you are getting an error, check to make sure that all of your account information is properly defined.

Want to learn more about the code in the Function template, or want to write your own server code? Checkout the Twilio Chat Identity Guide for the underlying concepts.

Now that the Twilio Function is set up, let's get the starter iOS app up and running.

モバイルアプリケーションのダウンロードと探求

To get going quickly, there are starter apps built as stand-alone Xcode 9 projects written in both Swift and Objective-C. Download one of them now:

どちらのアプリケーションも CocoaPods パッケージマネージャーで構築されており、GitHub(Objective-CSwift)から入手できます。CocoaPods をインストールし、ご希望のアプリケーションをダウンロードして解凍します。ターミナルでアプリケーションのディレクトリーに移動し、次のコマンドを実行して依存性をインストールします。

pod install

これにより、すべての CocoaPods プロジェクトと同様に、ChatQuickstart.xcworkspace という名前の新しいファイルが生成されます。以降、このプロジェクトを使うときは、次のコマンドを実行してこのファイルを開きます。

open ChatQuickstart.xcworkspace

You will need to go into ViewController.m or ChatViewController.swift and modify the URL for your Twilio Function there - each Twilio user will have a different domain to use for their Twilio Functions.

Objective-C:

const NSString* kTokenURL =  @"https://YOUR_DOMAIN_HERE.twil.io/chat-token";

Swift:

let tokenURL = "https://YOUR_TWILIO_FUNCTION_DOMAIN_HERE.twil.io/chat-token"

Start sending yourself a few messages - they should start appearing in a UITableView in the starter app.

準備完了

You're all set! From here, you can start building your own application. For guidance on integrating the iOS SDK into your existing project, head over to our install guide. If you'd like to learn more about how Programmable Chat works, you might want to dive into our user identity guide, which talks about the relationship between the mobile app and the server.

次のセクション:ユーザーアイデンティティとアクセストークンの管理 »

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。