アプリ内メッセージ¶
アプリ内メッセージはSDKをインストールするだけで利用できます。表示タイミングはメッセージ作成時に メッセージ表示トリガー で指定してください。
ただし以下のケースに当てはまる場合、実装の追加/変更を行う必要があります。
実装の追加/変更が必要なケース¶
アプリ起動時にスプラッシュスクリーンを表示したり画面遷移をしている場合¶
アプリの実装がこのケースの場合、アプリ内メッセージの表示トリガーを「アプリ起動」にした際にメッセージがうまく表示されないことがあります。
この場合、以下の手順でSDK APIを利用して起動時のアプリ内メッセージの表示タイミングをずらすことが可能です。
ご利用中のSDKバージョンが5以上の場合¶
まず、 disableInAppMessagesOnForegroundTransition
を setup
より前に呼び出してください。
#import <Repro/Repro.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[Repro disableInAppMessagesOnForegroundTransition];
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
import Repro
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
Repro.disableInAppMessagesOnForegroundTransition()
Repro.setup(token: "YOUR_APP_TOKEN")
...
}
import io.repro.android.Repro;
...
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
...
Repro.disableInAppMessagesOnForegroundTransition()
Repro.setup(this, "YOUR_APP_TOKEN");
...
}
}
ReproCpp::disableInAppMessagesOnForegroundTransition();
using UnityEngine;
public class MyBehaviour : MonoBehaviour {
void Start () {
...
Repro.DisableInAppMessagesOnForegroundTransition()
Repro.Setup ("YOUR_APP_TOKEN");
...
}
}
onDeviceReady: function() {
app.receivedEvent('deviceready');
Repro.disableInAppMessagesOnForegroundTransition();
Repro.setup("YOUR_APP_TOKEN");
}
//
// call disableInAppMessageOnActive method in your native code like shown bellow.
//
// iOS(Objective-C): AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro disableInAppMessagesOnForegroundTransition];
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
// Android(Java): MainApplication
@Override
public void onCreate() {
super.onCreate();
Repro.disableInAppMessagesOnForegroundTransition()
Repro.setup(this, "YOUR_APP_TOKEN");
...
}
//
// call disableInAppMessagesOnForegroundTransition method in your native code like shown bellow.
//
// iOS(Objective-C): AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[Repro disableInAppMessagesOnForegroundTransition];
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
// Android(Java): MyApplication
@Override
public void onCreate() {
super.onCreate();
Repro.disableInAppMessagesOnForegroundTransition();
Repro.setup(this, "YOUR_APP_TOKEN");
...
}
さらに、スプラッシュスクリーンの表示が終わったタイミングで enableInAppMessagesOnForegroundTransition
を呼び出してください。
[Repro enableInAppMessagesOnForegroundTransition];
Repro.enableInAppMessagesOnForegroundTransition()
import io.repro.android.Repro;
public class MyActivity extends Activity {
protected void someFunc() {
...
// you should pass current visible activity to enableInAppMessagesOnForegroundTransition()
Repro.enableInAppMessagesOnForegroundTransition(this);
...
}
}
ReproCpp::enableInAppMessagesOnForegroundTransition();
Repro.EnableInAppMessagesOnForegroundTransition();
Repro.enableInAppMessagesOnForegroundTransition();
Repro.enableInAppMessagesOnForegroundTransition();
await Repro.enableInAppMessagesOnForegroundTransition();
注釈
disableInAppMessagesOnForegroundTransition は、アプリ起動時にスプラッシュスクリーンを採用している場合に活用することを想定した「アプリ起動」イベント専用のメソッドです。 「アプリ起動」以外のイベントが表示トリガーであるメッセージを表示するタイミングの制御をすることはできません。
ご利用中のSDKバージョンが5未満の場合¶
まず、 disableInAppMessageOnActive
を setup
より前に呼び出してください。
#import <Repro/Repro.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[Repro disableInAppMessageOnActive];
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
import Repro
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
Repro.disableInAppMessageOnActive()
Repro.setup(token: "YOUR_APP_TOKEN")
...
}
import io.repro.android.Repro;
...
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
...
Repro.disableInAppMessageOnActive()
Repro.setup(this, "YOUR_APP_TOKEN");
...
}
}
#include "ReproCpp.h"
bool AppDelegate::applicationDidFinishLaunching() {
...
ReproCpp::disableInAppMessageOnActive();
ReproCpp::setup("YOUR_APP_TOKEN");
...
}
using UnityEngine;
public class MyBehaviour : MonoBehaviour {
void Start () {
Repro.DisableInAppMessageOnActive ();
Repro.Setup ("YOUR_APP_TOKEN");
}
}
onDeviceReady: function() {
app.receivedEvent('deviceready');
Repro.disableInAppMessageOnActive();
Repro.setup("YOUR_APP_TOKEN");
}
//
// call disableInAppMessageOnActive method in your native code like shown bellow.
//
// iOS(Objective-C): AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro disableInAppMessageOnActive];
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
// Android(Java): MainApplication
@Override
public void onCreate() {
super.onCreate();
Repro.disableInAppMessageOnActive()
Repro.setup(this, "YOUR_APP_TOKEN");
...
}
// Flutter SDK does not support this feature under SDK version 5.
さらに、メッセージを表示しても問題ないタイミングで showInAppMessage
を呼び出してください。
[Repro showInAppMessage];
Repro.showInAppMessage()
import io.repro.android.Repro;
public class MyActivity extends Activity {
protected void someFunc() {
...
// you should pass current visible activity to showInAppMessage()
Repro.showInAppMessage(this);
...
}
}
ReproCpp::showInAppMessage();
Repro.ShowInAppMessage ();
Repro.showInAppMessage();
Repro.showInAppMessage();
// Flutter SDK does not support this feature under SDK version 5.
注釈
disableInAppMessageOnActive は、アプリ起動時にスプラッシュスクリーンを採用している場合に活用することを想定した「アプリ起動」イベント専用のメソッドです。 「アプリ起動」以外のイベントが表示トリガーであるメッセージを表示するタイミングの制御をすることはできません。
アプリ起動直後に実行されるイベント(「アプリ起動」以外)をアプリ内メッセージの表示トリガーに利用する場合¶
SDKはアプリフォアグラウンド後に表示すべきアプリ内メッセージの情報をサーバから取得します。 このためアプリ起動直後(例えばAndroidの場合、1つ目のActivityのonResumeなど)では情報取得が完了しておらず、メッセージが表示されない可能性があります。
この場合は、アプリ内メッセージの表示トリガーを「アプリ起動」に変更するか、当該イベントの実行を遅延させるなどをご検討ください。
画面遷移前後に実行されるイベントをアプリ内メッセージの表示トリガーに利用する場合¶
画面遷移前後にアプリ内メッセージを表示しようとすると、描画タイミングの影響によりメッセージが表示されない可能性があります。
以下の表を参考に、アプリ内メッセージの表示トリガーに利用するイベントの実装箇所を見直しください。
iOS
実行タイミング | ダイアログ、オーバーレイ | バナー |
---|---|---|
viewDidLoad | × | × |
viewWillAppear | ◯ | ◯ |
viewDidAppear | ○ | ◯ |
viewWillDisappear | ◯ | ◯ |
viewDidDisappear | ○ | × |
Android
実行タイミング | ダイアログ、オーバーレイ | バナー |
---|---|---|
onCreate | × | × |
onStart | × | × |
onResume | ○ | ◯ |
onPause | × | × |
onStop | ○ | ◯ |
onDestroy | ○ | ◯ |
onRestart | × | × |
警告
Androidはアプリ内メッセージを表示する時点でresumeの状態であるActivityがなければメッセージを表示できません。
ユニバーサルリンク/アプリリンクを使用する場合¶
端末に表示されたプッシュ通知およびアプリ内メッセージに設定されたリンクをタップした際に実行されるURLには、ユニバーサルリンク(またはアプリリンクと呼ばれる)を指定することが可能です。 (簡単のため、以下ではこれらをユニバーサルリンクと呼びます)
アプリにてユニバーサルリンクの実行時の処理を追加するには、以下の通り実装を行う必要があります。 (ここで設定された動作は、プッシュ通知およびアプリ内メッセージ対し有効となります。)
ユニバーサルリンクのURLパターンを登録する¶
ユニバーサルリンクを利用するためには、まずユニバーサルリンクのURLのパターン(正規表現)を指定する必要があります。
この指定は、iOSの場合は AppDelegate
または .plist
ファイル、Androidの場合は Application
継承クラス または AndroidManifest.xml
ファイルのどちらか一方に記述することで行うことができます。
// AppDelegate.m
#import <Repro/Repro.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro addOpenUrlFilterRegEx:@"https://example\\.com/page/"];
[Repro addOpenUrlFilterRegEx:@"your-domain\\.com/.+\?universal=true"];
...
}
// .plist file
/*
<dict>
<key>RPROpenUrlFilterRegExList</key>
<array>
<string>https://example\.com/page/</string>
<string>your-domain\.com/.+\?universal=true</string>
</array>
...
</dict>
*/
// MyApplication.java
import io.repro.android.Repro;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Repro.addOpenUrlFilterRegEx("https://example\\.com/page/");
Repro.addOpenUrlFilterRegEx("your-domain\\.com/.+\\?universal=true");
...
}
...
}
// AndroidManifest.xml
// To specify multiple URL patterns, enter them separated by commas.
<application>
...
<meta-data
android:name="io.repro.android.OpenUrlFilterRegExList"
android:value="https://example\\.com/page/;your-domain\\.com/.+\\?universal=true">
</meta-data>
</application>
// AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
Repro.add(openUrlFilterRegEx: "https://example\\.com/page/")
Repro.add(openUrlFilterRegEx: "your-domain\\.com/.+\\?universal=true")
...
}
// .plist file
/*
<dict>
<key>RPROpenUrlFilterRegExList</key>
<array>
<string>https://example\.com/page/</string>
<string>your-domain\.com/.+\?universal=true</string>
</array>
...
</dict>
*/
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
// YourAppNameScene.cpp
bool YourAppName::init() {
ReproCpp::addOpenUrlFilterRegEx("https://example\\.com/page/");
ReproCpp::addOpenUrlFilterRegEx("your-domain\\.com/.+\\?universal=true");
...
}
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
Please follow native iOS and Android instructions in order to add the filters
to the plist/AndroidManifest files or the main AppDelegate/Application classes.
ユニバーサルリンク実行時の処理を登録する¶
次に、ユニバーサルリンクが実行された際に動作するコールバック処理を実装します。 処理内には、例えばURLのパターンに応じて画面遷移を行う動作などを記述します。
#import <Repro/Repro.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Repro setOpenUrlCallback:^(NSURL *url) {
if ([url.host isEqualToString:@"example.com"]) {
// In case of your universal link perform navigation, present content, ...
handleUniversalLink(url);
}
}];
...
[Repro setup:@"YOUR_APP_TOKEN"];
...
}
// Set a callback that is executed everytime an URL is about to be opened
Repro.setOpenUrlCallback { url in
if url.host == "example.com" {
// In case of your universal link perform navigation, present content, ...
handleUniversalLink(url)
}
}
...
Repro.setup(token: "YOUR_APP_TOKEN")
...
import io.repro.android.Repro;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// In order to execute a callback when a push notification is tapped,
// the callback must be set in Application, not Activity.
Repro.setOpenUrlCallback(new Repro.OpenUrlCallback() {
// ** This callback method is executed in the main thread **
@Override
public void onOpened(Uri uri) {
if ("example.com".equals(uri.getHost())) {
// In case of your universal link perform navigation, present content, ...
}
}
});
...
Repro.setup(this, YOUR_APP_TOKEN);
...
}
...
}
Repro.setOpenUrlCallback((uri) { // uri is of type Uri
debugPrint("Universal Link Callback Handler received: " + uri.toString());
});
// Somewhere before Repro.Setup(...)
Repro.SetOpenUrlCallback(uri => // uri is of type Uri
{
Debug.Log("Universal Link Callback Handler received: " + uri.ToString());
});
bool YourAppName::init() {
ReproCpp::addOpenUrlFilterRegEx(...);
ReproCpp::setOpenUrlCallback([](const char *url) {
if (strcmp(url, "example.com") == 0) {
// In case of your universal link perform navigation, present content, ...
}
});
ReproCpp::setup("YOUR_APP_TOKEN")
...
}
Repro.setOpenUrlCallback(function(url) { // url is of type String
alert('Universal Link Callback Handler received: ' + url);
if (url.includes("http://example.org")) {
// In case of your universal link perform navigation, present content, ...
}
});
Repro.setOpenUrlCallback( (url) => { // url is of type String
console.log('Universal Link Callback Handler received: ' + url);
if (url.includes("http://example.org")) {
// In case of your universal link perform navigation, present content, ...
}
});
注釈
Cocos2d-xをご利用の場合のみ、別途ブリッジ処理の実装が必要です。 実装方法の詳細は ブリッジクラスの追加 を参照してください。