首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnityEngine.iOS.NotificationServices.CancelLocalNotification不删除通知

UnityEngine.iOS.NotificationServices.CancelLocalNotification不删除通知
EN

Stack Overflow用户
提问于 2018-01-12 19:48:59
回答 1查看 695关注 0票数 0

我目前正在构建一个类来处理我在iOS上的Unity3D游戏的通知。但是当我使用UnityEngine.iOS.NotificationServices.CancelLocalNotification (nt);时,预定的通知不会发生任何变化。

有没有人能帮我指点一下如何让它工作?

作为另一种选择,我可以使用UnityEngine.iOS.NotificationServices.CancelAllLocalNotifications,但那样就不那么优雅了。

我在iPhone6S上使用Unity 2017.2.0f3和iOS 11.2.1。

代码语言:javascript
复制
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);


}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-15 20:36:55

解决了。里面有个窃听器。if (nt.userInfo "type“==”早上“)应该是if (nt.userInfo "type".ToString() ==”上午“)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48225713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档