sunagimoブログ

主にUnityに関する技術を取り上げます

【Unity】Package Managerにモバイル通知の機能が追加されていた件(2)

本記事で扱うUnityのバージョンは「Unity2018.3.7f1」です。


前回
sunagimo-app.hatenablog.com




本日はAPIを見ていきます。

https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.0/manual/index.html

https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.0/api/Unity.Notifications.Android.AndroidNotification.html

 

まずAPIを使用する前に、AndroidiOSで宣言が必要。

using Unity.Notifications.Android;
using Unity.Notifications.iOS;

 

通知の作成
 

Android

AndroidNotification
f:id:sunagimo_app:20190227012620p:plain


指定できるパラメーターは、以下。

・Color(通知テンプレートの色?っぽい)
・FireTime(通知をする時間)
・LargeIcon(通知の大きいアイコン、/Assets/Plugins/Android/res/drawableに置く)
・Number(バッジの数)
・RepeatInterval (繰り返し間隔)
・ShouldAutoCancel(ユーザーが触れると自動的に消去される?よくわからない)
・SmallIcon(通知の小さいアイコン、大きいアイコンと同じ場所に入れておく)
・Style(通知のカスタムスタイル)
・Text(通知の本文)
・Title (通知のタイトル)
・UsesStopwatch (通知時刻フィールドをタイムスタンプではなく、ストップウォッチとして表示するか。よくわからない)


iOS

iOSNotification
f:id:sunagimo_app:20190227014032p:plain


指定できるパラメーターは、以下。

・Badge(バッジの数)
・Body(通知の本文)
・CategoryIdentifier(カテゴリ識別子)
・ForegroundPresentationOption(アプリの実行中に通知の地域を表示するための表示オプション?よくわからない)
・Identifier(識別子)
・ShowInForeground(アプリが起動中に通知アラートを表示するか)
・Subtitle(サブタイトル)
・ThreadIdentifier(宣言?よくわからない)
・Title(タイトル)
・Trigger(通知の配信をトリガーする条件、ここで通知時間も設定するらしい)



通知の送信


Android

SendNotification
f:id:sunagimo_app:20190227015103p:plain

作成したAndroidNotificationとチャンネル名を引数に渡します。
返ってくるIDは後々更新する際に使用可能。


iOS

ScheduleNotification
f:id:sunagimo_app:20190227015308p:plain

作成したiOSNotificationを引数として渡します。



通知の削除・全削除(届いてないものに関して)


Android

(通知の削除)
CancelScheduledNotification
f:id:sunagimo_app:20190227020657p:plain

通知を送った際のIdを引数に渡します。


(通知の全削除)
CancelAllScheduledNotifications
f:id:sunagimo_app:20190227020642p:plain


iOS

(通知の削除)
RemoveScheduledNotification
f:id:sunagimo_app:20190227020227p:plain

作成した際の識別子を引数として渡します。



(通知の全削除)
RemoveAllScheduledNotifications
f:id:sunagimo_app:20190227020543p:plain



通知の取得


Android

CheckScheduledNotificationStatus
f:id:sunagimo_app:20190227021405p:plain

API23(Android OS6.0)より使用可能。
通知を送る際のIdを引数に渡します。



iOS

GetScheduledNotifications
f:id:sunagimo_app:20190227021451p:plain

Androidとは異なり、スケジュールされている通知の情報がすべて返ってきます。



モバイル通知を実装するにあたって、基本的に必要なものをまとめてみました。


それと、最後に記事を書いてて思ったのですが、
iOSの通知にはすでに、NotificationServicesというAPIが用意されています。
docs.unity3d.com

これから両方生き残るということはないかと思いますが、
どちらが死にどちらかが生き残るのかと。

公式からはおそらく何も来ていないのでどうなるのでしょうかね…



次回は、実際にソースコードを書いて、
コードやデモの紹介もしていきます。