初期化¶
アプリの起動時に以下の手順でSDKの初期化処理を行います。
メッセージブリッジの設定¶
-
空のGameObjectを作成します。(既存のGameObjectでも可能)


-
フォルダ Assets / RichFlyerPluginScript の下にある RFMessageBridge.cs を任意のGameObjectにアタッチします。


初期化¶
アプリ起動時に呼ばれるスクリプト内で、初期化メソッドを実行します。
// Class RichFlyer.RFPluginScript
static void Initialize(string targetObjectName, RFNotificationReceiver receiver, RFCompleted onResult)
| パラメータ | 内容 |
|---|---|
| targetObjectName | メッセージブリッジ(RFMessageBridge.cs)をアタッチしたGameObjectの名前 |
| receiver | 通知が開封イベントを受け取るレシーバー |
| onResult | 結果リスナー |
通知開封イベントレシーバー¶
端末の通知欄からプッシュ通知が開封された時に呼び出されます。
通知に設定したアクションボタンがタップされた場合は、その情報が取得できます。
delegate void RFNotificationReceiver(string buttonTitle, string buttonValue, string buttonValueType, ulong buttonIndex, string extendedProperty);
| パラメータ | 内容 |
|---|---|
| buttonTitle | ボタンのタイトル |
| buttonValue | ボタンに設定した値 |
| buttonValueType | カスタムアクションの種類。 http: "https"または"http"で始まるurl scheme: カスタムスキームで始まるurl |
| buttonIndex | ボタンのインデックス |
| extendedProperty | 拡張プロパティの値 |
結果リスナー¶
delegate void RFCompleted(bool result, long code, string message);
| パラメータ | 内容 |
|---|---|
| result | 成否 |
| code | エラーコード |
| message | エラーメッセージ |
エラーコード¶
| エラーコード | 内容 | 予想される原因 |
|---|---|---|
| 401 | 認証失敗 | 認証トークンが不正か、期限切れの可能性があります。 アプリの再起動または requestAuthorization を呼ぶことで解消する可能性があります。 |
| 404 | サービス不明 | 管理サイトで取得したSDK実行キーが指定されていない可能性があります。 SDK実行キーの確認方法 |
| 600 | 通信エラー | RichFlyerサーバへの接続に失敗しています。通信環境の悪化等が考えられます。 |
| 601 | デバイストークン不明 | OSから発行されるデバイストークンがRichFlyer SDKに渡されていないか失われた可能性があります。 アプリの再起動または requestAuthorization を呼ぶことで解消する可能性があります。 |
| 602 | 認証トークン不明 | デバイストークンの登録に失敗している可能性があります。 アプリの再起動または requestAuthorization を呼ぶことで解消する可能性があります。 |
| 603 | 認証トークン不明 | デバイストークンの登録に失敗している可能性があります。 アプリの再起動または requestAuthorization を呼ぶことで解消する可能性があります。 |
| 604 | SDK実行キー不明 | SDK実行キーが指定されていない可能性があります。 |
実装例¶
実装例
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RichFlyer;
public class RFBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
RFPluginScript.Initialize("RichFlyer", RFNotificationReceiver, (bool result, long code, string message) =>
{
if (result)
{
Debug.Log("RF-initialize succeeded");
}
else
{
Debug.Log("RF-initialize failed");
}
});
}
// Update is called once per frame
void Update()
{
}
// 通知が開封されたら呼ばれる
public static void RFNotificationReceiver(string buttonTitle, string buttonValue, string buttonValueType, ulong buttonIndex, string extendedProperty)
{
// カスタムアクションボタンのラベル
Debug.Log($"RF-ButtonTitle:{buttonTitle}");
// カスタムアクションに設定されている値
Debug.Log($"RF-ButtonValue:{buttonValue}");
// カスタムアクションの種類(url,scheme)
Debug.Log($"RF-ButtonValueType:{buttonValueType}");
// カスタムアクションボタンのインデックス
Debug.Log($"RF-ButtonIndex:{buttonIndex}");
// 拡張プロパティ
Debug.Log($"RF-ExtendedProperty:{extendedProperty}");
}
}