Unity SDK 기본 통합 가이드
이 가이드는 Pushwoosh Unity SDK를 애플리케이션에 통합하는 과정을 안내합니다.
전제 조건
Anchor link to통합 단계
Anchor link to1. Pushwoosh Unity SDK 추가
Anchor link toPackages/manifest.json에 다음을 추가하세요:
{ "dependencies": { "com.pushwoosh.unity.core": "6.2.7", "com.pushwoosh.unity.android": "6.2.7", "com.pushwoosh.unity.ios": "6.2.7" }, "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org", "scopes": ["com.pushwoosh"] } ]}필요한 플랫폼 패키지만 추가하세요. 예를 들어, iOS만 타겟팅하는 경우 com.pushwoosh.unity.android는 생략합니다.
Unity에서 Window > Package Manager > + > Add package from git URL로 이동하여 다음 URL을 하나씩 추가하세요:
https://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.corehttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.androidhttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.iosGitHub Releases에서 Pushwoosh.unitypackage를 다운로드하고 Assets > Import Package > Custom Package를 통해 가져옵니다.
2. External Dependency Manager 설치
Anchor link toSDK는 네이티브 Android 및 iOS 의존성을 해결하기 위해 External Dependency Manager for Unity (EDM4U)가 필요합니다.
Packages/manifest.json에 다음 scoped registry를 추가하세요:
{ "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": ["com.google.external-dependency-manager"] } ]}그런 다음 의존성에 패키지를 추가하세요:
"com.google.external-dependency-manager": "1.2.183"3. SDK 초기화
Anchor link toPushNotificator.cs 스크립트를 생성하고 씬의 모든 GameObject에 연결하세요:
using UnityEngine;using System.Collections.Generic;
public class PushNotificator : MonoBehaviour{ void Start() { Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnRegisteredForPushNotifications += (token) => { Debug.Log("Push token: " + token); };
Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += (error) => { Debug.Log("Registration failed: " + error); };
Pushwoosh.Instance.RegisterForPushNotifications(); }}다음 항목을 교체하세요:
XXXXX-XXXXX를 Pushwoosh Application Code로 교체하세요.XXXXXXXXXXXX를 Firebase 프로젝트 번호(Android 전용)로 교체하세요.
4. iOS 네이티브 설정
Anchor link to4.1 기능
Anchor link toUnity에서 iOS 프로젝트를 빌드한 후, 생성된 Xcode 프로젝트를 열고 Signing & Capabilities에서 다음 기능을 추가하세요:
- 푸시 알림
- 백그라운드 모드에서 원격 알림 선택
긴급 알림(iOS 15 이상)의 경우, 긴급 알림 기능도 추가하세요.
4.2 Info.plist
Anchor link toInfo.plist에 Pushwoosh Device API Token을 추가하세요:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>4.3 메시지 전송 추적
Anchor link toXcode 프로젝트에 Notification Service Extension 타겟을 추가하세요. 이는 iOS에서 정확한 전송 추적 및 리치 미디어를 위해 필요합니다.
확장 타겟을 추가하려면 네이티브 가이드를 따르세요.
5. Android 네이티브 설정
Anchor link to5.1 Firebase 구성 파일 추가
Anchor link togoogle-services.json 파일을 Unity 프로젝트의 Assets 디렉토리에 배치하세요.
5.2 Pushwoosh 메타데이터 추가
Anchor link toPushwoosh Device API Token을 Assets/Plugins/Android/AndroidManifest.xml의 <application> 태그 내에 추가하세요:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />6. 프로젝트 실행
Anchor link to- 대상 플랫폼에서 프로젝트를 빌드하고 실행하세요.
- 메시지가 표시되면 푸시 알림 권한을 부여하세요.
- Pushwoosh Control Panel로 이동하여 푸시 알림을 보내세요.
확장 통합
Anchor link to이 단계에서 푸시 알림을 보내고 받을 수 있습니다. 아래 섹션에서는 핵심 SDK 기능에 대해 설명합니다.
푸시 알림 이벤트 리스너
Anchor link toSDK는 푸시 알림을 처리하기 위한 두 가지 이벤트 리스너를 제공합니다:
OnPushNotificationsReceived— 푸시 알림이 도착했을 때 트리거됩니다OnPushNotificationsOpened— 사용자가 알림을 탭했을 때 트리거됩니다
SDK 초기화 중에 이러한 리스너를 설정하세요:
void Start(){ Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnPushNotificationsReceived += (payload) => { Debug.Log("Push received: " + payload); };
Pushwoosh.Instance.OnPushNotificationsOpened += (payload) => { Debug.Log("Push opened: " + payload); };
Pushwoosh.Instance.RegisterForPushNotifications();}사용자 구성
Anchor link to사용자를 식별하고 속성을 설정하여 푸시 알림을 개인화하세요:
// 교차 기기 추적을 위한 사용자 ID 설정Pushwoosh.Instance.SetUserId("user-123");
// 사용자 이메일 설정Pushwoosh.Instance.SetEmail("user@example.com");
// ID와 이메일을 모두 사용하여 사용자 설정Pushwoosh.Instance.SetUser("user-123", new List<string> { "user@example.com" });
// 선호 언어 설정Pushwoosh.Instance.SetLanguage("en");태그는 기기에 할당된 키-값 쌍으로, 사용자 세분화 및 타겟 메시징을 가능하게 합니다:
// 문자열 태그Pushwoosh.Instance.SetStringTag("favorite_category", "electronics");
// 정수 태그Pushwoosh.Instance.SetIntTag("purchase_count", 5);
// 목록 태그Pushwoosh.Instance.SetListTag("interests", new List<object> { "sports", "music", "tech" });
// 모든 태그 가져오기Pushwoosh.Instance.GetTags((tags, error) => { if (error != null) { Debug.Log("Error: " + error.Message); return; } foreach (var tag in tags) { Debug.Log(tag.Key + ": " + tag.Value); }});사용자 행동을 분석하고 자동화된 메시지를 트리거하기 위해 사용자 행동을 추적하세요:
// 로그인 이벤트 추적Pushwoosh.Instance.PostEvent("login", new Dictionary<string, object> { { "username", "user-123" }, { "login_type", "email" }});
// 구매 이벤트 추적Pushwoosh.Instance.PostEvent("purchase", new Dictionary<string, object> { { "product_id", "SKU-001" }, { "price", 29.99 }, { "currency", "USD" }});통신 환경설정
Anchor link to사용자가 프로그래밍 방식으로 푸시 알림을 수신하거나 거부하도록 허용하세요:
// 통신 활성화Pushwoosh.Instance.SetCommunicationEnabled(true);
// 통신 비활성화Pushwoosh.Instance.SetCommunicationEnabled(false);
// 현재 상태 확인bool isEnabled = Pushwoosh.Instance.IsCommunicationEnabled();배지 관리
Anchor link to지원되는 플랫폼에서 앱 배지 번호를 제어하세요:
// 배지를 특정 숫자로 설정Pushwoosh.Instance.SetBadgeNumber(3);
// 배지 증가Pushwoosh.Instance.AddBadgeNumber(1);
// 배지 지우기Pushwoosh.Instance.SetBadgeNumber(0);문제 해결
Anchor link to통합 과정에서 문제가 발생하면 지원 및 커뮤니티 섹션을 참조하세요.