はじめに
「Unity3D Android notification plugin」を Unity プロジェクトに導入することで
iOS / Android でローカル通知を実装できるようになります
使用例
5 秒後に通知
LocalNotification.SendNotification ( id : 1, delayMs : 5000, title : "Title", message : "Long message text", bgColor : new Color32( 255, 68, 68, 255 ) );
5 秒後に大きなアイコン付きで通知
LocalNotification.SendNotification ( id : 1, delayMs : 5000, title : "Title", message : "Long message text with big icon", bgColor : new Color32( 255, 68, 68, 255 ), sound : true, vibrate : true, lights : true, bigIcon : "app_icon" );
5 秒後に通知アクション
var a1 = new LocalNotification.Action( "background", "In Background", this ); a1.Foreground = false; var a2 = new LocalNotification.Action( "foreground", "In Foreground", this ); LocalNotification.SendNotification ( id : 1, delayMs : 5000, title : "Title", message : "Long message text with actions", bgColor : new Color32( 255, 68, 68, 255 ), sound : true, vibrate : true, lights : true, bigIcon : null, soundName : "boing", channel : "default", actions : new [] { a1, a2 } ); public void OnAction( string identifier ) { Debug.Log( "Got action " + identifier ); }
5 秒後にリピート通知
LocalNotification.SendRepeatingNotification ( id : 1, delayMs : 5000, timeoutMs : 60000, title : "Title", message : "Long message text", bgColor : new Color32( 255, 68, 68, 255 ) );
通知をキャンセル
LocalNotification.CancelNotification( 1 );
小さなアイコンを設定する方法
「Assets/Plugins/Android/res/*」フォルダ内の「notify_icon_small.png」を差し替える
大きなアイコンを設定する方法
「Assets/Plugins/Android/res/*」フォルダ内に「notify_icon_big.png」を追加して
「bigIcon」引数に「notify_icon_big」と設定する
アプリアイコンを使用する場合は「bigIcon」引数に「app_icon」と設定する
カスタムサウンドを使用する方法
Android では「Assets/Plugins/Android/res/raw」フォルダ内に .mp3 か .ogg を追加する
iOS では「Assets/StreamingAssets」フォルダ内に .wav か .caf、.aiff を追加する
そして「sound」引数に「true」を設定し、「soundName」引数に、
拡張子抜きのサウンドファイル名を設定する