Skip to content

アンドロイド・プッシュ通知の統合

このリファレンス記事では、Unityプラットフォーム用のAndroidプッシュ通知の統合について説明します。

これらの手順は、Firebase Cloud Messaging (FCM) とプッシュを統合するためのものです。

ADMの統合手順については、Unity ADMのドキュメントを参照してください。

ステップ 1:Firebaseを有効にする

開始するには、Firebase Unity セットアップドキュメントに従ってください。

ステップ 2: Firebaseの認証情報を設定する

Firebaseサーバーキーと送信者IDをBrazeダッシュボードに入力する必要があります。Firebase Developers Console]58 にログインし、Firebase プロジェクトを選択します。次に、Settingsの Cloud Messagingを選択し、Server KeyとSender IDをコピーします:

Brazeのアプリ設定ページの「設定の管理」でAndroidアプリを選択します。次に、FirebaseCloud Messaging Server Keyフィールドに Firebase Server Key を、FirebaseCloud Messaging SenderID フィールドに Firebase Sender ID を入力します。

ステップ 3: 自動プッシュ統合の実装

Braze SDKは、Firebaseクラウドメッセージングサーバーへのプッシュ登録を自動的に処理し、デバイスにプッシュ通知を受信させることができます。

UnityエディターはBrazeの設定オプションを表示します。このエディタでは、”Automate Unity Android Integration”、”Push Notification Firebase Push”、”Push Configuration Handle Push Deeplinks Automatically”、”Push Configuration Push Notification HTML Rendering Enabled”、および “Set Push Deleted “を設定します。/Opened/Received Listeners” are set. The fields “Firebase Sender ID”, “Small/Large Icon Drawable”, “Default Notification Accent Color” are also provided.]62

  • Firebase Cloud Messagingの自動登録が有効になりました。
    デバイスのFCMプッシュトークンを自動的に取得して送信するようにBraze SDKに指示します。
  • Firebase Cloud Messaging の送信者 ID
    Firebase コンソールからの送信者 ID。
  • ディープリンクを自動的にプッシュする
    プッシュ通知がクリックされたときに、SDKがディープリンクを開くか、アプリを開くかを処理するかどうか。
  • 小さな通知アイコン
    Drawableは、プッシュ通知を受信するたびに小さなアイコンとして表示される必要があります。アイコンが提供されていない場合、通知はアプリケーションアイコンをスモールアイコンとして使用します。

ステップ 4: プッシュリスナーを設定する

プッシュ通知のペイロードをUnityに渡したり、ユーザーがプッシュ通知を受信したときに追加の処理を行いたい場合、Brazeにはプッシュ通知リスナーを設定するオプションがあります。

Brazeのアプリ設定ページの「設定の管理」でAndroidアプリを選択します。次に、Firebase Server KeyをPush Notification Settingsフィールドに、Firebase Sender IDをPush Notification SettingsIDフィールドに入力します。

プッシュ受信リスナー

プッシュ受信リスナーは、ユーザーがプッシュ通知を受信したときに起動されます。Unityにプッシュペイロードを送信するには、ゲームオブジェクトの名前を設定し、Set Push Received Listenerの下に受信リスナーコールバックメソッドをプッシュします。

プッシュオープンリスナー

ユーザーがプッシュ通知をクリックしてアプリを起動すると、プッシュ・オープン・リスナーが起動します。Unityにプッシュペイロードを送信するには、Set Push Opened Listenerでゲームオブジェクトの名前とプッシュオープンリスナーのコールバックメソッドを設定します。

プッシュ削除リスナー(Androidのみ)

削除されたプッシュ・リスナーは、ユーザーがプッシュ通知をスワイプしたり、削除したりしたときに発行されます。Unityにプッシュペイロードを送信するには、Set Push Deleted Listenerでゲームオブジェクトの名前とプッシュ削除リスナーのコールバックメソッドを設定します。

プッシュ・リスナーの実装例

次の例では、PushNotificationReceivedCallbackPushNotificationOpenedCallbackPushNotificationDeletedCallback のコールバック・メソッド名を使って、BrazeCallback ゲーム・オブジェクトを実装している。

この実装例の図は、前のセクションで述べたBrazeの設定オプションと、C#のコードスニペットを示しています]63

```csharp public class MainMenu :MonoBehaviour { void PushNotificationReceivedCallback(string message) { #if UNITY_ANDROID Debug.Log(“PushNotificationReceivedCallback message: “ + message); PushNotification pushNotification = new PushNotification(message); Debug.Log(“Push Notification received: “ + pushNotification);
#elif UNITY_IOS ApplePushNotification pushNotification = new ApplePushNotification(message); Debug.Log(“Push received Notification event: “ + pushNotification);
`endif`
()

void PushNotificationOpenedCallback(string message) { #if UNITY_ANDROID Debug.Log(“PushNotificationOpenedCallback message: “ + message); PushNotification pushNotification = new PushNotification(message); Debug.Log(“Push Notification opened: “ + pushNotification);
#elif UNITY_IOS ApplePushNotification pushNotification = new ApplePushNotification(message); Debug.Log(“Push opened Notification event: “ + pushNotification);
`endif`
()

void PushNotificationDeletedCallback(string message) { #if UNITY_ANDROID Debug.Log(“PushNotificationDeletedCallback message: “ + message); PushNotification pushNotification = new PushNotification(message); Debug.Log(“Push Notification dismissed: “ + pushNotification);
`endif` () } ```

実施例

Braze Unity SDKリポジトリのサンプルプロジェクトには、FCMを含む完全な動作サンプルアプリが含まれています。

アプリ内リソースへのディープリンク

Brazeは標準的なディープリンク(ウェブサイトのURLやAndroidのURIなど)をデフォルトで扱うことができますが、カスタムディープリンクを作成するには、追加のマニフェスト設定が必要です。

設定ガイダンスについては、アプリ内リソースへのディープリンクを参照してください。

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