기본 콘텐츠로 건너뛰기

[Unity3D] 유니티 내장 로컬 푸쉬 기능

 유니티 내장 로컬 푸쉬 기능
 - iOS에서만 가능, Android는 직접 개발하던가 Plugin 사용 


먼저 등록을 해주고 ( 등록 안하면 작동 안함 )
public void InitNotification()
{
 #if UNITY_ANDROID
 #elif UNITY_IOS
 UnityEngine.iOS.NotificationServices.RegisterForNotifications(
  UnityEngine.iOS.NotificationType.Alert |
  UnityEngine.iOS.NotificationType.Sound
 );
 #endif
}
시간을 정해서 등록해준다.( 3일동안 접속 안할 경우 알림이 오게 한다면 )
public void ScheduleNotification() { //Affer 3 Day string _body01 = "다시 시작해볼까요?"; #if UNITY_IOS UnityEngine.iOS.LocalNotification notiWake = new UnityEngine.iOS.LocalNotification(); DateTime theTime_Wake = DateTime.Now; theTime_Wake = theTime_Wake.AddHours(24*3); Debug.Log("theTime_Wake:"+theTime_Wake); notiWake.fireDate = theTime_Wake; notiWake.alertAction = "타이틀"; notiWake.alertBody = _body01; notiWake.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName; UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notiWake); #elif UNITY_ANDROID #endif }
취소 함수를 만들어서 앱이 중지되거나 종료 될때 스케쥴을 등록하고
앱이 다시 실행되면 알람을 모두 취소시킨다.
public void CancelAllNotification()
{
 #if UNITY_ANDROID
 #elif UNITY_IOS
 UnityEngine.iOS.NotificationServices.ClearLocalNotifications();
 UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications();
 #endif
}
void OnApplicationQuit() {
 CancelAllNotification();
 ScheduleNotification();
}
void OnApplicationPause( bool pauseStatus )
{
 if( pauseStatus )
 {
  CancelAllNotification();
  ScheduleNotification();
 }
 else
 {
  CancelAllNotification();
 }
}


댓글

이 블로그의 인기 게시물