gpt4 book ai didi

iOS 本地通知测试

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:52 26 4
gpt4 key购买 nike

在测试我的本地通知时,出于某种原因,在我的 iOS 设备上设置日期和时间不会触发我的本地通知出现。我的通知的触发日期设置为 future 几天。如果我真的等了几天,我就会看到我的本地通知。

为什么我在设备上设置日期和时间后看不到本地通知?

下面是一个示例:

            playNotification.FireDate = DateTime.Now.AddHours(71.67f);
playNotification.AlertAction = "Alert text";
playNotification.AlertBody = "Alert body";
playNotification.SoundName = UILocalNotification.DefaultSoundName;
playNotification.ApplicationIconBadgeNumber = badgeCount;
UIApplication.SharedApplication.ScheduleLocalNotification(playNotification);

我应该提到我将“AddHours”更改为“AddSeconds”并通过等待指定的秒数来测试它,并且通知按预期触发。但是以某种方式更改我设备上的日期和时间并没有。

最佳答案

您需要设置通知的timeZone。默认情况下,timeZone 是根据您所在的位置设置的,因此如果您手动更改日期和时间,它不会受到影响。为此,您需要将 timeZone 设置为 systemTimeZone()

像这样:

    notification.timeZone = NSTimeZone.systemTimeZone()

我知道这是 swift,但我对 objective-c 知之甚少。希望这可以帮助。 :)

关于iOS 本地通知测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22334385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com