Skip to content


プッシュ統合

ステップ1:APNトークンをアップロードする。

Before you can send an iOS push notification using Braze, you need to upload your .p8 push notification file, as described in Apple’s developer documentation:

  1. In your Apple developer account, go to Certificates, Identifiers & Profiles.
  2. Under Keys, select All and click the add button (+) in the upper-right corner.
  3. Under Key Description, enter a unique name for the signing key.
  4. Under Key Services, select the Apple Push Notification service (APNs) checkbox, then click Continue. Click Confirm.
  5. Note the key ID. Click Download to generate and download the key. Make sure to save the downloaded file in a secure place, as you cannot download this more than once.
  6. In Braze, go to Settings > App Settings and upload the .p8 file under Apple Push Certificate. You can upload either your development or production push certificate. To test push notifications after your app is live in the App Store, its recommended to set up a separate workspace for the development version of your app.
  7. When prompted, enter your app’s bundle ID, key ID, and team ID. You’ll also need to specify whether to send notifications to your app’s development or production environment, which is defined by its provisioning profile.
  8. When you’re finished, select Save.

ステップ2: プッシュ機能を有効にする

プロジェクト設定で、[機能] タブの [プッシュ通知] 機能がオンになっていることを確認します。

開発用と実稼働用のプッシュ証明書が別々にある場合は、[全般] タブの [署名を自動的に管理する] チェックボックスをオフにしてください。これにより、Xcode の自動コード署名機能は開発署名のみを行うため、ビルド構成ごとに異なるプロビジョニングプロファイルを選択できるようになります。

[一般] タブが表示されているXcode プロジェクトの設定。このタブでは、[署名を自動的に管理する] オプションはオフになっています。

ステップ3: プッシュ通知に登録する

ユーザーのデバイスを APNs に登録するには、アプリの application:didFinishLaunchingWithOptions: デリゲートメソッド内に適切なコードサンプルが含まれている必要があります。アプリケーションのメインスレッドですべてのプッシュ統合コードを呼び出すようにしてください。

Braze には、プッシュアクションボタンをサポートするデフォルトのプッシュカテゴリーも用意されており、プッシュ登録コードに手動で追加する必要があります。その他の統合ステップについては、プッシュアクションボタンを参照のこと。

UserNotification フレームワークの使用(iOS 10以降)

iOS 10で導入された UserNotifications フレームワーク (推奨) を使用している場合は、アプリデリゲートの application:didFinishLaunchingWithOptions: メソッドに以下のコードを追加します。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
  UNAuthorizationOptions options = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  if (@available(iOS 12.0, *)) {
  options = options | UNAuthorizationOptionProvisional;
  }
  [center requestAuthorizationWithOptions:options
                        completionHandler:^(BOOL granted, NSError * _Nullable error) {
                          [[Appboy sharedInstance] pushAuthorizationFromUserNotificationCenter:granted];
  }];
  [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
  UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
  [[UIApplication sharedApplication] registerForRemoteNotifications];
  [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if #available(iOS 10, *) {
  let center = UNUserNotificationCenter.current()
  center.delegate = self as? UNUserNotificationCenterDelegate
  var options: UNAuthorizationOptions = [.alert, .sound, .badge]
  if #available(iOS 12.0, *) {
    options = UNAuthorizationOptions(rawValue: options.rawValue | UNAuthorizationOptions.provisional.rawValue)
  }
  center.requestAuthorization(options: options) { (granted, error) in
    Appboy.sharedInstance()?.pushAuthorization(fromUserNotificationCenter: granted)
  }
  UIApplication.shared.registerForRemoteNotifications()
} else {
  let types : UIUserNotificationType = [.alert, .badge, .sound]
  let setting : UIUserNotificationSettings = UIUserNotificationSettings(types:types, categories:nil)
  UIApplication.shared.registerUserNotificationSettings(setting)
  UIApplication.shared.registerForRemoteNotifications()
}

UserNotifications フレームワークを使用しない場合

UserNotifications フレームワークを使用していない場合は、アプリデリゲートのapplication:didFinishLaunchingWithOptions: メソッドに次のコードを追加します。

1
2
3
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
1
2
3
4
let types : UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert
var setting : UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
UIApplication.shared.registerUserNotificationSettings(setting)
UIApplication.shared.registerForRemoteNotifications()

ステップ 4:Braze にプッシュトークンを登録する

APNs の登録が完了したら、次のメソッドを変更し結果として得られる deviceToken を Braze に渡し、ユーザーがプッシュ通知を使用できるようにする必要があります。

application:didRegisterForRemoteNotificationsWithDeviceToken: メソッドに次のコードを追加します。

1
[[Appboy sharedInstance] registerDeviceToken:deviceToken];

アプリの application(_:didRegisterForRemoteNotificationsWithDeviceToken:) メソッドに次のコードを追加します。

1
Appboy.sharedInstance()?.registerDeviceToken(deviceToken)

ステップ5: プッシュ処理を有効にする

以下のコードは受信したプッシュ通知を Braze に渡すコードで、プッシュ分析とリンク処理のログを取るために必要です。アプリケーションのメインスレッドですべてのプッシュ統合コードを呼び出すようにしてください。

iOS 10以降

iOS 10以降に対してビルドする場合は、UserNotifications フレームワークを統合し、以下の手順を実行することをお勧めします。

アプリケーションの application:didReceiveRemoteNotification:fetchCompletionHandler: メソッドに次のコードを追加します。

1
2
3
[[Appboy sharedInstance] registerApplication:application
                didReceiveRemoteNotification:userInfo
                      fetchCompletionHandler:completionHandler];

次に、アプリの (void)userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: メソッドに次のコードを追加します。

1
2
3
[[Appboy sharedInstance] userNotificationCenter:center
                 didReceiveNotificationResponse:response
                          withCompletionHandler:completionHandler];

フォアグラウンドでのプッシュ通知処理

アプリがフォアグラウンドにある間にプッシュ通知を表示するには、userNotificationCenter:willPresentNotification:withCompletionHandler: を実装します。

1
2
3
4
5
6
7
8
9
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
  if (@available(iOS 14.0, *)) {
    completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner);
  } else {
    completionHandler(UNNotificationPresentationOptionAlert);
  }
}

フォアグラウンド通知がクリックされると、iOS 10のプッシュデリゲート userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: が呼び出され、Braze はプッシュクリックイベントをログに記録します。

アプリの application(_:didReceiveRemoteNotification:fetchCompletionHandler:) メソッドに次のコードを追加します。

1
2
3
Appboy.sharedInstance()?.register(application,
                                            didReceiveRemoteNotification: userInfo,
                                            fetchCompletionHandler: completionHandler)

次に、アプリの userNotificationCenter(_:didReceive:withCompletionHandler:) メソッドに次のコードを追加します。

1
2
3
Appboy.sharedInstance()?.userNotificationCenter(center,
                                               didReceive: response,
                                               withCompletionHandler: completionHandler)

フォアグラウンドでのプッシュ通知処理

アプリがフォアグラウンドにある間にプッシュ通知を表示するには、userNotificationCenter(_:willPresent:withCompletionHandler:) を実装します。

1
2
3
4
5
6
7
8
9
func userNotificationCenter(_ center: UNUserNotificationCenter,
                              willPresent notification: UNNotification,
                              withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
  if #available(iOS 14.0, *) {
    completionHandler([.list, .banner]);
  } else {
    completionHandler([.alert]);
  }
}

フォアグラウンド通知がクリックされると、iOS 10のプッシュデリゲート userNotificationCenter(_:didReceive:withCompletionHandler:) が呼び出され、Braze はプッシュクリックイベントをログに記録します。

iOS 10より前のバージョン

iOS 10では、プッシュがクリックされたときに application:didReceiveRemoteNotification:fetchCompletionHandler: を呼び出さないように動作が更新されました。そのため、iOS 10以降に対応するビルドに更新せず、UserNotifications フレームワークを使用する場合、古いスタイルのデリゲートの両方から Braze を呼び出す必要があり、以前の統合とは一線を画しています。

iOS 10より前の SDK に対してビルドするアプリの場合は、以下の手順を使用します。

プッシュ通知でオープントラッキングを有効にするには、アプリの application:didReceiveRemoteNotification:fetchCompletionHandler: メソッドに次のコードを追加します。

1
2
3
[[Appboy sharedInstance] registerApplication:application
                didReceiveRemoteNotification:userInfo
                      fetchCompletionHandler:completionHandler];

iOS 10でプッシュ分析をサポートするには、アプリの application:didReceiveRemoteNotification: デリゲートメソッドに次のコードも追加する必要があります。

1
2
[[Appboy sharedInstance] registerApplication:application
                didReceiveRemoteNotification:userInfo];

プッシュ通知でオープントラッキングを有効にするには、アプリの application(_:didReceiveRemoteNotification:fetchCompletionHandler:) メソッドに次のコードを追加します。

1
2
3
Appboy.sharedInstance()?.register(application,
  didReceiveRemoteNotification: userInfo,
  fetchCompletionHandler: completionHandler)

iOS 10でプッシュ分析をサポートするには、アプリの application(_:didReceiveRemoteNotification:) デリゲートメソッドに次のコードも追加する必要があります。

1
2
Appboy.sharedInstance()?.register(application,
  didReceiveRemoteNotification: userInfo)

ステップ 6: ディープリンク

プッシュからアプリへのディープリンクは、標準のプッシュ統合ドキュメントを介して自動的に処理されます。アプリ内の特定の場所にディープリンクを追加する方法について詳しくは、高度なユースケースを参照してください。

ステップ 7:単体テスト (オプション)

今行った統合手順のテストカバレッジを追加するには、[プッシュ単体テスト] を実装します。

「このページはどの程度役に立ちましたか?」
New Stuff!