メニュー

Expand
ページを評価:

iOS プッシュ通知を設定する

In this guide, we'll go through all the necessary steps to get your Apple push credentials configured with Twilio Notifications. The end result is a Twilio Credential which you can then use to receive notifications in your iOS app. Let's get started!

アクション

Step 1 - Setup an App ID

Log into your Apple development account and click on Identifiers under the Certificates, Identifiers & Profiles section. This will show a list of identifiers, including App IDs.

Option 1- Existing App ID

If your App ID is already on this list, click on it and a list of capabilities will popup.

  1. Check the 'Push Notifications' option.
  2. Don't worry about the Configure button right now, just click the Save button in the upper right.

Option 2- New App ID

If your App ID isn't on this list, click the "+" symbol to add a new App ID.

  1. Choose App IDs and click the Continue button in the upper right.
  2. Give your app a description as you see fit.
  3. Give it an Explicit Bundle ID that matches the bundle identifier in Xcode (such as com.twilio.notify.NotifyQuickstart).
  4. Under Capabilities check Push Notifications
  5. Click the Continue button
  6. Click the Register button to confirm your new App ID and create it.

Step 2 - Create a Certificate

Now we'll want to create a push notification certificate. This will enable your app to receive notifications. You can either make a development certificate or a production certificate. For this guide, we'll make a development certificate. We recommend you use Xcode managed certificate.

オプション1 - Xcode Managed Certificates

  1. Xcodeプロジェクト上で、開発中のiOSアプリケーションのターゲットのGeneralペインに移動します。

2. Signingセクションで、"Automatically manage signing"のチェックをオンにします:

Xcodeでの自動署名

3. If you are using the Quickstart app and see a provisioning error message you may need to rename the bundle id to a unique identifier.

Bundle Identifierエラー

To do so, go to https://developer.apple.com/account/resources/certificates/list and give the bundle a new name. Then, enter your new identifier in the Identity section of the General pane:

一意なBundle Identifier

Xcodeのcapabilitiesタブに移動し、"Push Notifications"がオンになっていることを確認してください:

プッシュ通知を有効にする

5. いくつかの方法で証明書が作成されたことを検証できます:

a. Apple developerポータルから:

1. Apple Developerポータルにサインインして、Certificates, IDs & Profileをクリックします。

サイドバーのCertificatesセクションで、検証したい証明書の種類に応じてDevelopment(開発用)またはProduction(本番用)から選択します。

b. 証明書がKeychainに保存されていることを確認してください:

1. ローカル上でキーチェーンアクセスを起動し、 左のサイドバーから「証明書」を選択します。 "iPhone"をキーワードに検索し、iPhoneの証明書をフィルタリングします。

2. 証明書の隣に展開できる三角形があれば、それはKeychainに秘密鍵が含まれていることを示していますのでダブルクリックします

6. おめでとうございます! Apple Developer iOS Push Service certificateが作成できました。 このプロセスで問題が発生した場合は、Appleのこちらのガイドを参照してください。

オプション2 - 証明書を手動で作成する

アプリケーション用にXcodeにより管理される証明書の使用をおすすめしますが、手動で証明書を作成することもまた可能です。

  1. Add a certificate on the Apple Developer Portal
  2. Under Services, select 'Apple Push Notification service SSL (Sandbox)'.
  3. Click 'Continue'
  4. Select the App ID you previously created in the textbox.
  5. Click 'Continue' again
  6. It will prompt you to create a Certificate Signing Request, with instructions on how to do it. Create one.
  7. Once you've created a CSR, click 'Continue'.
  8. Upload it.
  9. Click 'Generate' to generate your certificate.

Congrats! You just created an Apple Development iOS Push Services certificate. Now you can download it and double click on it locally to add it to your Keychain access.

Step 3 - Create a Credential for Twilio

In Keychain Access, go to the 'My Certificates' Category in the lefthand sidebar.

  1. Right-click your new certificate. It should be labeled "Apple Development iOS Push Services".
  2. Choose "Export"
  3. Save it as cred.p12. (Leave the password blank)

This is your credential file. We're going to extract your certificate key and private key from this file. We need these 2 keys to create a Twilio Credential.

Create a Certificate Key

ターミナルで次のコマンドを実行します。

openssl pkcs12 -in cred.p12 -nokeys -out cert.pem -nodes

Create a Private Key

ターミナルで次のコマンドを実行します。

openssl pkcs12 -in cred.p12 -nocerts -out key.pem -nodes

Then this command to process the RSA key

openssl rsa -in key.pem -out key.pem

Then you can paste your credentials into the web console to upload them.

Strip anything outside of "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" boundaries and outside of "-----BEGIN RSA PRIVATE KEY-----" and "-----END RSA PRIVATE KEY-----" boundaries before pasting them. Check the 'Sandbox' button if you made a development certificate. Sandbox is synonymous with development mode.

Create APNS Credentials

After you've pasted them in, click save. If everything went well, you'll see a SID appear on the new page. Copy it to your clipboard, you will need it in the next step. Congrats, you just made a Twilio Push Credential!

Configure your Twilio Service to use your APNS credentials

これにより、1 つのアカウントで複数のアプリケーションを構築できます。これらのアプリケーションを分離するには、アプリケーションのすべてのデータと設定を保持する Service インスタンスを作成する必要があります。

Specifically you need to configure your Service instance to use the Credential that contains your APNS certificate and private key. You can do that using the Services page in the Twilio console. You will need to update your Service with the APNS credential SID.

Configure APNS Credential SID

If you are just getting started, set up this APN credential first, then create your Service first by clicking the red plus button on the services console page.

You are ready to go. Check out the iOS Quickstart to start sending notifications.

ページを評価:

ヘルプが必要ですか?

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

        
        
        

        フィードバックくださりありがとうございます!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        ステップ1

        Get link

        Get a free personal referral link here

        ステップ2:

        Give $10

        Your user signs up and upgrade using link

        ステップ3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more