Firebase 콘솔에 애플리케이션 프로젝트를 추가하고 구성 파일인 google-services.json
파일 을 다운로드한 후, LTV 대시 보드에서 API 키와 sender ID를 업데이트합니다.
이 링크 를 통해서 sender ID 및 API 키를 얻는 방법을 확인하세요.
다음으로 https://firebase.google.com/download/unity에서 Firebase Unity SDK를 다운로드하여 앱에 Firebase Unity SDK를 추가합니다.
Unity에서 Assets> Import Package> Custom Package 메뉴 항목을 선택합니다.
다운로드 한 Firebase Unity SDK에서FirebaseMessaging.unitypackage
패키지를 가져옵니다.
Unity 패키지 가져오기 창이 나타나면 Import 버튼을 클릭합니다.
Dex 파일 충돌을 방지하려면Assets/Plugins/Android/google-play-service-lib/libs
에서 google-play-service 파일을 모두 삭제하십시오.
다음 줄의 추가 하십시오.
#define USE_FIREBASE_MESSAGING
프로젝트 스크립트에서 Firebase 클라우드 메시징을 설정하기 전에 다음 코드로 Firebase SDK를 초기화합니다.
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp, i.e.
// app = Firebase.FirebaseApp.DefaultInstance;
// where app is a Firebase.FirebaseApp property of your application class.
// Set a flag here indicating that Firebase is ready to use by your
// application.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
스크립트에서 Firebase 클라우드 메시징을 설정합니다.
public void Start() {
Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
}
public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token) {
UnityEngine.Debug.Log("Received Registration Token: " + token.Token);
}
public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e) {
UnityEngine.Debug.Log("Received a new message from: " + e.Message.From);
}
진입 Activity를 설정합니다.
SDK가 Unity에 추가되면 Firebase Unity SDK는 Assets/Plugins/AndroidManifest.xml에서 UnityPlayerActivity
를 MessagingUnityPlayerActivity
로 대체합니다.
FCM SDK가 기존 AndroidManifest.xml 파일을 덮어 쓴 후 다음 Tapjoy Activity 를 다시 추가해줘야 합니다.
<activity android:name="com.tapjoy.TJAdUnitActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" android:hardwareAccelerated="true" />
<activity android:name="com.tapjoy.TJContentActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity android:name="com.tapjoy.mraid.view.Browser" android:configChanges="orientation|keyboardHidden|screenSize" />
<activity android:name="com.tapjoy.mraid.view.ActionHandler" android:configChanges="orientation|keyboardHidden|screenSize" />
<service android:name="com.google.firebase.messaging.MessageForwardingService" android:exported="false" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<receiver android:name="com.tapjoy.InstallReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<receiver android:name="com.tapjoy.TapjoyReceiver" />
이 파일들은 기본 UnityPlayerActivity가 'onStop', 'onRestart' lifecycle 관련 로직을 적절하게 수행하지 않고, Firebase 클라우드 메시징이 수신 메시지를 처리하는데 필요한 'onNewIntent' 메소드가 구현되어있지 않기 때문에 제공됩니다.
UnityPlayerActivity를 사용하는 대신 직접 시작 Activity를 구현하는 경우 앱이 백그라운드에 있을 때 알림을 받으려면, onNewIntent
구현 시 우회방법을 적용해야 합니다.
FCM 자동 사용을 방지하려면 AndroidManifest.xml
에 다음 코드를 추가하세요.
<?xml version="1.0" encoding="utf-8"?>
<application>
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
</application>
참고 : Firebase SDK는 플랫폼 수준이 아닌 프로젝트 수준으로 Unity 프로젝트에 추가됩니다. Unity iOS에 FCM을 구현하지 않더라도 Google\ _service.plist
파일을 Assets에 추가해야합니다. Google\ _service.plist
파일을 가져 오려면 Firebase 콘솔에서 iOS 앱을 만들고 구성 plist 파일을 생성, 다운로드하여 Assets 폴더에 추가합니다.
참고문서: https://firebase.google.com/docs/cloud-messaging/unity/client
Tapjoy 위도우에서 GCM Sender ID를 설정하세요. ","로 구분하여 여러 Sender ID를 등록 할 수 있습니다.
푸시 알림을 보내기 전에 API 서버키 및 Sender ID를 구성해야합니다. 탭조이 대시보드에서 "설정 > 앱설정"으로 이동 한 다음 왼쪽 메뉴 바에서 "푸시 인증서" 메뉴를 선택하여 키와 Sender ID를 구성하십시오.
최근 Unity FCM 연동 변경 사항으로 인해 애플리케이션이 백그라운드 / 비활성 상태 일 때 MessageReceived 콜백이 호출되지 않습니다. 앱이 백그라운드/비활성 상태일 때 알림을 받으려면 Android 네이티브 코드에서 리시버를 구현해야합니다.
com.google.firebase.messaging.cpp.ListenerService
의 하위 클래스를 만들고(Unity FCM이 C ++ 인터페이스를 사용하므로) onMessageReceived를 재정의하여 Tapjoy.setReceiveRemoteNotification을 호출하도록 연동합니다. import com.google.firebase.messaging.RemoteMessage;
import com.google.firebase.messaging.cpp.ListenerService;
import com.tapjoy.Tapjoy;
public class FCMMessageService extends ListenerService {
@Override
public void onMessageReceived(RemoteMessage message) {
// super.onMessageReceived(message);
Tapjoy.setReceiveRemoteNotification(getApplicationContext(), message.getData());
}
}
<service android:name=".pushnotification.FCMMessageService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Tapjoy 대시보드를 통해 푸시 알림 (FCM 메시지)을 보내면 애플리케이션 아이콘이 기본 알림 아이콘으로 표시됩니다.
애플리케이션 프로젝트의 AndroidManifest.xml
파일의 <application>
태그에 다음과 같이 리소스를 지정하여 알림 아이콘을 변경할 수 있습니다.
<manifest ...>
...
<application ...>
...
<meta-data android:name="com.tapjoy.notification.icon" android:resource="@drawable/ic_notify"/>
...
</application>
...
</manifest>
SDK 11.9.0 이상에는 사용자의 푸시 허용 여부를 확인 할 수 있는 API를 제공합니다.
/**
* @brief 대상 플랫폼이 Android 일 때 푸시 알림이 비활성화 된 경우 true를 반환합니다.
* 그렇지 않으면 false를 반환합니다.
*/
public static bool IsPushNotificationDisabled()
/**
* @brief 푸시 알림 비활성화 여부를 설정합니다. (Android 만 해당)
* @param disabled
* 푸시 알림을 비활성화하려면 true
*/
public static void SetPushNotificationDisabled(bool disabled)
Unity 플러그인에는 iOS 푸시 알림용 C# 인터페이스가 없으므로 빌드과정에서 생성되는 Xcode 프로젝트를 수정해야합니다. 다음과 같은 방법으로 Xcode 프로젝트를 수정하십시오. 푸시 알림 지원을 위해 다음 델리게이트 메서드에서 지정된 Tapjoy 메서드를 호출합니다.
// 원격 알림이 등록되면 호출됩니다.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[Tapjoy setDeviceToken:deviceToken];
}
// 사용자가 푸시 메시지를 클릭하면 호출됩니다.
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[Tapjoy setApplicationLaunchingOptions:launchOptions];
}
// 사용자가 앱을 재생하는 동안 푸시 메시지를 받으면 호출됩니다.
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
[Tapjoy setReceiveRemoteNotification:userInfo];
}
푸시 알림 서비스를 등록하는 것을 잊지 마십시오. 서비스를 등록하지 않으면 권한허용에 대한 다이얼로그 팝업을 볼 수 없습니다.
// Registering for remote notifications
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
// iOS 8 Notifications
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
} else {
// iOS < 8 Notifications
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
자세한 내용은 iOS Local and Remote Notification Programming Guide문서를 참조하세요.
푸시 알림을 보내려면 Apple 푸시 알림 서비스 인증서가 필요합니다. 자세한 내용은 로컬 알림 및 원격 알림 가이드를 참조하세요. 인증서를 받으면 Tapjoy 대시 보드에 업로드하세요. 자세한 내용은 푸시 인증서 구성 방법을 참조하세요. Tapjoy 대시보드에서 "설정 > 앱설정"으로 이동 한 다음 왼쪽 메뉴 바에서 "푸시 인증서"를 선택하여 인증서 파일을에 업로드하십시오.
탭조이와 동시에 다른 푸시 제공자 푸시 서버스를 사용할 수 있나요?
가능합니다. 이 문서를 참조하세요.
내 푸시 인증서가 곧 만료됩니다.
만료되기 전에 현재 인증서를 새 인증서로 교체하세요.
사용자를 특정 앱 지점으로 리디렉션 할 수 있습니까?
예. 사용자 지정 페이로드를 사용하여 사용자를 리디렉션 할 수 있습니다. 이 문서를 참조하세요.