300x250

0. Mobile Notifications 구현해야 하는 이유

 

게임 앱에서 푸시 알림을 사용하는 이유는 다양합니다. 이러한 알림은 사용자 경험을 개선하고 게임의 참여도를 높일 수 있는 강력한 도구입니다. 


재참여 유도: 게임을 잊지 않고 계속해서 플레이하도록 유도할 수 있습니다. 푸시 알림을 통해 사용자에게 게임에 대한 업데이트, 이벤트, 할인, 새로운 콘텐츠 등을 알릴 수 있습니다. 이렇게 하면 사용자들이 게임에 다시 참여하고 새로운 콘텐츠나 기능을 경험하도록 유도할 수 있습니다.

이벤트 및 경쟁 참여 유도: 게임 내 이벤트, 경쟁, 토너먼트 등에 사용자를 참여시킬 수 있습니다. 푸시 알림을 통해 이러한 이벤트에 대한 알림과 참여 방법, 보상 등을 전달할 수 있습니다. 사용자는 이러한 알림을 통해 게임에서의 목표를 인식하고 참여 동기를 얻을 수 있습니다.

소셜 상호작용 장려: 게임에서의 소셜 상호작용은 매우 중요합니다. 푸시 알림을 통해 사용자에게 친구 요청, 선물, 도움 요청 등을 알릴 수 있습니다. 또한 다른 플레이어와의 상호작용을 촉진하기 위해 이벤트에 대한 초대, 공유, 리더보드 업데이트 등을 알릴 수도 있습니다.

개인화된 경험 제공: 푸시 알림은 사용자에게 개인화된 경험을 제공할 수 있는 효과적인 방법입니다. 사용자의 선호도, 플레이 스타일, 진행 상황 등을 고려하여 맞춤형 알림을 전송할 수 있습니다. 이렇게 하면 사용자는 게임에서 더 많은 관심과 참여를 보일 수 있습니다.

중요한 업데이트 및 경고 전달: 푸시 알림을 사용하면 게임 내 중요한 업데이트, 경고 또는 이슈에 대해 사용자에게 신속하게 알릴 수 있습니다. 예를 들어, 서버 다운타임, 보안 경고, 결제 확인 등을 사용자에게 알릴 수 있습니다.

푸시 알림은 게임 애플리케이션의 사용자 참여와 유지에 매우 유용한 도구입니다. 그러나 알림의 빈도와 타이밍은 사용자 경험에 큰 영향을 줄 수 있으므로 신중하게 계획하고 구성해야 합니다. 사용자의 플레이 스타일과 선호도를 고려하여 푸시 알림을 사용하는 것이 좋습니다.

 

유니티에서 Mobile Notifications에 관련된 패키지를 제공하고 있기때문에 쉽게 구현할 수 있었습니다.

 

 

 

1. 프로젝트 생성

안드로이드 셋팅

 

2. 패키지 추가

3. 샘플도 임폴트 Import 해줍니다.

4.

샘플 생성확인 후 NotificationsManager.cs 스크립트 작성

using NotificationSamples;
using System;
using UnityEngine;

public class NotificationsManager : GameNotificationsManager
{
    // Public
    ////////////////////////////////////////////////////////////////////////////////////////

    public const string channel1 = "channel1";
    public const string channel2 = "channel2";
    public const string channel3 = "channel3";

    // 알람푸쉬 권한
    public void Init(bool isAlarmAccept = true, bool isNightAlarmAccept = true)
    {
        _isAlarmAccept = isAlarmAccept;
        _isNightAlarmAccept = isNightAlarmAccept;
    }

    private void SendNotification(string title, string body, DateTime deliveryTime, int? badgeNumber = null,
                                 bool reschedule = false, string channelId = null,
                                 string smallIcon = null, string largeIcon = null)
    {
        // 알람푸쉬 권한 체크
        if (!_isAlarmAccept)
            return;
        
        // 야간푸쉬 권한 체크
        if(!_isNightAlarmAccept)
        {
            bool isNight = CheckNightTime(deliveryTime);
            if (isNight)
                return;
        }

        IGameNotification notification = instance.CreateNotification();
        if (notification == null)
        {
            return;
        }

        notification.Title = title;
        notification.Body = body;
        notification.Group = !string.IsNullOrEmpty(channelId) ? channelId : channel1;
        notification.DeliveryTime = deliveryTime;
        notification.SmallIcon = smallIcon;
        notification.LargeIcon = largeIcon;

        if (badgeNumber != null)
        {
            notification.BadgeNumber = badgeNumber;
        }

        PendingNotification notificationToDisplay = instance.ScheduleNotification(notification);
        notificationToDisplay.Reschedule = reschedule;
    }

    // Private
    ////////////////////////////////////////////////////////////////////////////////////////
    private GameNotificationsManager instance;

    private float _tenSecond = 10f;
    private float _twentySecond = 20f;
    private bool _isAlarmAccept = true;
    private bool _isNightAlarmAccept = true;

    private int nightStartHour = 22;
    private int nightEndHour = 6;

    private void Awake()
    {
        instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        var c1 = new GameNotificationChannel(channel1, "channel1", "channel1 notifications");
        var c2 = new GameNotificationChannel(channel2, "channel2", "channel2 notifications");
        var c3 = new GameNotificationChannel(channel3, "channel3", "channel3 notifications");


        instance.Initialize(c1, c2, c3);

        instance.Platform.CancelAllScheduledNotifications();
    }

    private void OnApplicationPause(bool pause)
    {
        if (pause)
        {
            RefreshNotifications();
        }
        else
        {
            //resume
            if (instance != null && instance.Platform != null)
            {
                instance.Platform.CancelAllScheduledNotifications();
            }

        }
    }

    private void OnApplicationQuit()
    {
        RefreshNotifications();
    }

    private void RefreshNotifications()
    {
        if (instance == null || instance.Platform == null)
        {
            return;
        }

        CancelAllNotifications();

        // 알람 허용자 체크
        if(_isAlarmAccept)
        {
            var title = "TITLE TEXT";
            SendNotification(title, "tenSecond", DateTime.Now.AddSeconds(_tenSecond));
            SendNotification(title, "twentySecond", DateTime.Now.AddSeconds(_twentySecond));
        }

    }

    private bool CheckNightTime(DateTime checkTime)
    {
        bool isNight = false;

        int hour = int.Parse(checkTime.ToString("HH"));

        if (hour < nightEndHour || hour >= nightStartHour)
            isNight = true;

        return isNight;
    }

}

 

5.  스크립트 넣어주고 빌드

 

 

 

 

 

참고문헌

Introduction | Mobile Notifications | 1.3.2 (unity3d.com)

 

300x250