유니티/유니티 C#

[유니티/C#] 모바일 푸시알림

진서박 2022. 8. 3. 20:25
반응형

 

https://assetstore.unity.com/packages/tools/integration/simple-android-notifications-free-68626?locale=ko-KR

 

Simple Android Notifications Free | 기능 통합 | Unity Asset Store

Use the Simple Android Notifications Free from Hippo on your next project. Find this integration tool & more on the Unity Asset Store.

assetstore.unity.com

에셋 추가로 간단하고 빠르게 푸시알림 구현이 가능하다.

 

사용 시에는

using Assets.SimpleAndroidNotifications; 

를 추가 해줘야한다.

 

// 앱이 일시정지 되었을 때 1분후에 푸시알림을 보내는 코드
private void OnApplicationPause(bool pause)
    {
        NotificationManager.CancelAll();	// 모든 알림 삭제
        if (pause)
        {
            isPaused = true;

            DateTime dateTime = DateTime.Now.AddMinutes(1);	
            TimeSpan time = dateTime - DateTime.Now;
            NotificationManager.SendWithAppIcon(time, title, content, Color.blue, NotificationIcon.Star);
            // 원하는 시간, 제목, 내용, 글자 색, 알림 아이콘 으로 푸시알림 발생

            Debug.Log("일시정지");
        }
        else
        {
            if (isPaused)
            {
                isPaused = false;
                Debug.Log("일시정지 해제");
            }
        }
    }
    
    // 앱이 꺼졌을 때 1분 후에 푸시알림을 보내는 코드
    private void OnApplicationQuit()
    {
        Debug.Log("게임 종료");
        DateTime dateTime = DateTime.Now.AddMinutes(1);
        TimeSpan time = dateTime - DateTime.Now;
        NotificationManager.SendWithAppIcon(time, title, content, Color.blue, NotificationIcon.Star); 
    }

테스트

 

반응형