iOS 本地通知测试

标签 ios datetime testing xamarin uilocalnotification

在测试我的本地通知时,出于某种原因,在我的 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/

相关文章:

r - 强制 ggplot 比例开始,例如第一年,第一个月等

shell 脚本 : What's the difference between using test and if statement?

testing - 在调用组件中的异步服务之前测试值是否设置正确

objective-c - 学习 Objective-C 来对 ios 设备进行编程后会发生什么?

ios - swift 中的 loadNibNamed 应该返回 Singleton 对象

ios - 以编程方式创建的 UITableView 不显示任何内容

perl - 为什么我的 Perl 测试会因使用编码 'utf8' 而失败?

iphone - iPhone 中导航栏按钮上的角标(Badge)

Python人类可读的日期差异

mysql - 选择最后一天时间范围为早上 7 点到午夜之间的所有 MySQL 记录