0

現在、iOS 用の Unity3D ゲームの通知を処理するクラスを作成しています。しかし、私が使用しているときUnityEngine.iOS.NotificationServices.CancelLocalNotification (nt);、スケジュールされた通知には何も起こりません。

誰かがこれを機能させる方法を教えてもらえますか?

別の方法として使用できますUnityEngine.iOS.NotificationServices.CancelAllLocalNotificationsが、それははるかにエレガントではありません。

iPhone 6SでUnity 2017.2.0f3とiOS 11.2.1を使用しています。

public void UpdateMorningNotifications()
{

    // Get all current scheduled morning notifications in a list. if they are type morning. erase them.
    UnityEngine.iOS.LocalNotification[] scheduledNotifications = UnityEngine.iOS.NotificationServices.scheduledLocalNotifications;

    Debug.Log ("NotificationScheduler/UpdateMorningNotifications - number of scheduledNotifications = " + scheduledNotifications.Length);

    foreach (UnityEngine.iOS.LocalNotification nt in scheduledNotifications) 
    {

        Debug.Log ("NotificationScheduler/UpdateMorningNotifications - clearing notification, type is " + nt.userInfo["type"] );
        if (nt.userInfo ["type"] == "morning") 
        {
            Debug.Log ("Its a morning nt, lets get rid of it!");
            UnityEngine.iOS.NotificationServices.CancelLocalNotification (nt);
            Debug.Log ("NotificationScheduler/UpdateMorningNotifications - clearing notification: " + nt.alertBody);
        }

    }


    // building, and adding notifications to notificationservices.
    DateTime fireDate = DateTime.Today;

    int summedInterval = 0;
    // fill up the morning timings list.
    foreach (int interval in MorningNotificationDayInterVals) 
    {   
        // adding new interval to firedate
        summedInterval = summedInterval + interval;
        fireDate = fireDate.AddDays (summedInterval);


        // if weekend fire at 10AM else 8 AM
        if (fireDate.DayOfWeek.ToString() == "Saturday" || fireDate.DayOfWeek.ToString() == "Sunday") {
            fireDate.AddHours (10);
        } else {
            fireDate.AddHours(8);
        }

        //generate notification with random title and the timing and add it to the batch.
        int morningTitleIndex = UnityEngine.Random.Range(0,morningTitles.Length);

        // generating a new notification.
        notification = GenerateNotification (morningTitles[morningTitleIndex], fireDate, "morning");

        // adding the notification to the batch.
        notificationBatch.Add (notification);
        Debug.Log("NotificationScheduler/UpdateMorningNotifications: Length of notificationBatch = " + notificationBatch.Count);
    }

    // Adding notifications to notificationsservices
    AddNotificationBatchToNotificationServices (notificationBatch);


}
4

1 に答える 1

0

解決しました。バグがありました。 if (nt.userInfo ["type"] == "morning") は if (nt.userInfo ["type"].ToString() == "morning") のはずです

于 2018-02-15T12:36:54.803 に答える