Unityで無料で使えるローカルプッシュ通知(レビュー版)が結構進化していて使い勝手が
良くなってきたので実装して色々試しています。
Unityモバイル通知
(翻訳すると分かりやすい)
できること)
・アプリ内に実装して時間を設定するとプッシュ通知が届く。
・アプリを完全終了しても設定しているプッシュ通知が届く・
・表示アイコンを設定できる。
・プッシュ通知をタップすると設定したアクションを起こせる※
質問は※の部分でマニュアルを見ると下記の様な設定をするとIntentのようにnotificationに保存することが
できデータを渡せるとのことですが
var notification = new AndroidNotification(); notification.IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}";
上のコードで設定したものをタップ時に取得するコードがよく分かりません。(サンプルに見当たらない)
(Jsonデータを取得しているような?)
分かる方教えてください。
コード全文
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; using Unity.Notifications.Android; public class LocalNotification : MonoBehaviour { int setTime; int nowTime; int seconds; int activeHour; int activeMin; int activeFlag; int activeSeconds; int cateId; string title; string message; string prefskeyHour; string prefskeyMin; string prefskeyActive; public Text identifierText; public Text idText; public Text channelText; public Text notificationText; // var identifier; string m_channelId = "english"; // Start is called before the first frame update void Start() { //通知用のチャンネルを作成する var c = new AndroidNotificationChannel { Id = m_channelId, Name = "hogehog", Importance = Importance.High, Description = "説明する", }; AndroidNotificationCenter.RegisterNotificationChannel(c); } void OnApplicationPause(bool pauseStatus) { uniNotification("タイトル", "message", 30); } public void uniNotification(string title, string message, int seconds){ var notification = new AndroidNotification(); notification.Title = title; notification.Text = message; notification.IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}"; notification.FireTime = DateTime.Now.AddSeconds(seconds); // if( CheckScheduledNotificationStatus(identifier) == NotificationStatus.Scheduled) // { // UpdateScheduleNotification(identifier, newNotification); // } else if( CheckScheduledNotificationStatus(identifier) == NotificationStatus.Unkown) // { //識別子を割り当てる var identifier = AndroidNotificationCenter.SendNotification(notification, m_channelId); identifierText.text = identifier.ToString(); // } //受信したNotificationをタップした時に取得するデータ var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent(); if(notificationIntentData != null) { var id = notificationIntentData.Id; var channel = notificationIntentData.Channel; var notificationValue = notificationIntentData.Notification; idText.text = id.ToString(); channelText.text = channel; notificationText.text = notificationValue.ToString(); // return notification.IntentData; } } int TimeChangedScript(int hour, int min) { DateTime now = DateTime.Now; int nowHour = now.Hour; int nowMinute = now.Minute; setTime = hour * 60 + min; nowTime = nowHour * 60 + nowMinute; if(setTime > nowTime){ seconds = (setTime - nowTime) * 60; }else{ seconds = (1440 + setTime - nowTime) * 60; //1440 = 24 * 60:時間を分にして加算 } return seconds; } }
フォーラムもあり、本当はそちらで質問するべきなのかもしれませんが
英語のやりとりのため、読むことはできますがそちらで質問するのには自信がありません。
また疑問に思っている事のやりとりはフォーラムには見当たりません。
よろしくお願いします。
環境)
PC: mac
Unity2018.2
言語:C#
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。