facebook twitter hatena line email

「Unity/ローカル通知」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(=アイコン画像が設定されない場合)
(アイコン画像が設定されない場合)
行29: 行29:
 
====アイコン画像が設定されない場合====
 
====アイコン画像が設定されない場合====
 
LocalPushNotification.cs内の
 
LocalPushNotification.cs内の
以下をMobileNotificationの設定のSmallとLargeのTypeにあわせて、SmallIconとLargeIconを設定する
+
以下をMobileNotificationの設定のSmallとLargeのIdentifierにあわせて、SmallIconとLargeIconを設定する
 
<pre>
 
<pre>
 
static private void SetAndroidNotification(string title, string message, int badgeCount, int elapsedTime, string cannelId)
 
static private void SetAndroidNotification(string title, string message, int badgeCount, int elapsedTime, string cannelId)
行38: 行38:
 
         Text = message,
 
         Text = message,
 
         Number = badgeCount,
 
         Number = badgeCount,
         SmallIcon = "Small",
+
         SmallIcon = "icon_0",
         LargeIcon = "Large",
+
         LargeIcon = "icon_1",
 
         FireTime = DateTime.Now.AddSeconds(elapsedTime)
 
         FireTime = DateTime.Now.AddSeconds(elapsedTime)
 
     };
 
     };

2024年9月13日 (金) 03:48時点における版

ローカル通知に使うライブラリMobile Notificationsをインストール

  1. window/package managerを選択
  2. 左上の+の右ドロップボックスが、InProjectになってれば、UnityRegistoryを選択
  3. Mobile Notificationsを選択
  4. インストール
  5. Assets/Editor/com.unity.mobile.notifications/にインストールされることを確認

設定

  1. Edit/Project Settings/Mobile Notifications

に設定画面がある

androidアイコン設定

  1. Androidタブ選択
  2. Notifications Iconを選択し、png画像をドラッグ&ドロップ
Small Icon 48x48
Large Icon 192x192
  • Smallアイコンは、通知の白黒アイコンで、背景は透過にする必要がある。
  • Largeアイコンは、通知とともに出るカラーアイコン。

以下エラーが出る場合

Specified texture can't be used because:
Read/Write is not enabled in the texture importer.

画像のInspectorのAdvancedを開いて、Read/Write Enabledにチェックを入れるとよい。

参考:https://traitam.hatenablog.com/entry/2020/04/05/133704

アイコン画像が設定されない場合

LocalPushNotification.cs内の 以下をMobileNotificationの設定のSmallとLargeのIdentifierにあわせて、SmallIconとLargeIconを設定する

static private void SetAndroidNotification(string title, string message, int badgeCount, int elapsedTime, string cannelId)
{
    var notification = new AndroidNotification
    {
        Title = title,
        Text = message,
        Number = badgeCount,
        SmallIcon = "icon_0",
        LargeIcon = "icon_1",
        FireTime = DateTime.Now.AddSeconds(elapsedTime)
    };

各種設定

android側

RescheduleOnDeviceRestart は、チェックをつけると、再起動時に、スケジュールが消えてしまったものを、再スケジュールする。

Schedule at exact timeは、正確なスケジュールを使うかどうか。

UseCustomActivityについて、ユーザーが通知をクリックしたときに開かれるアクティビティを上書きする場合は、有効にします。

公式:ttps://docs.unity3d.com/ja/Packages/com.unity.mobile.notifications@2.1/api/Unity.Notifications.NotificationSettings.AndroidSettings.html

csサンプル

以下からLocalPushNotificationを追加

https://qiita.com/syou007/items/dd5cbd8be7590e12f3cf

push通知発行

LocalPushNotification.RegisterChannel("channelId", "アプリ名(チャンネル名)", "説明");
LocalPushNotification.AddSchedule("プッシュ通知タイトル", "内容", 1, 60, "channelId");

第3引数のbadgeCountは、スマホアプリボタンのicon右上に表示される通知件数の数字。

push通知削除

LocalPushNotification.AllClear();

Androidビルド時にenableUncompressedNativeLibsエラー

MobileNotificationがエラーを起こしている。 エラー詳細

WARNING:The option setting 'android.bundle.enableUncompressedNativeLibs=false' is deprecated.
The current default is 'true'.
It will be removed in version 8.0 of the Android Gradle plugin.

対応方法: MobileNotificationを2(2.2.1)系から1.4.4へ

参考

https://qiita.com/syou007/items/dd5cbd8be7590e12f3cf