gpt4 book ai didi

windows-phone-8 - Windows Phone 8 自定义每小时范围动态磁贴更新频率

转载 作者:行者123 更新时间:2023-12-03 23:36:44 25 4
gpt4 key购买 nike

当我在寻找这个问题的答案时,我只遇到开发人员正在寻找越来越频繁地更新其应用程序的动态磁贴的方法。我想要相反的东西。

看到我正在开发一个天气应用程序,我希望它每小时更新一次,但仅限于特定的小时范围。也就是说,我不希望用户能够每小时更新一次磁贴,因为 1) 人们 sleep 和 2) 我使用的 API 仅对每天的前 1,000 次调用免费。换句话说,用户不需要每小时更新一次,我也负担不起让他们选择的代价。

例如,是否可以让动态磁贴从上午 8 点到晚上 11 点每小时更新一次,而从中午 12 点到早上 7 点不调用任何电话?

最佳答案

如果您在 ScheduledAgent 中调用 API,只需将调用包装在检查时间的 if block 中。我也有类似的需要,每天更新一次磁贴(它正在倒计时直到圣诞节)。

此代码在我的 ScheduledAgent.cs 文件中。它检查日期(应该只在 12 月和 26 日之前触发)并设置倒计时,然后仅在圣诞节早上发送 toast 通知。它应该是一个很好的例子,说明如何在后台任务中将 API 调用限制在 dat 的设定时间。

if (DateTime.Now.Month == 12 && DateTime.Now.Day < 26)
{
//number of days until the 25th
var countdown = ((new DateTime(DateTime.Now.Year, 12, 25).DayOfYear) - DateTime.Now.DayOfYear);

if (secondaryTile != null)
{
var imageString = "/Images/Tiles/" + countdown + ".png";
var newTileData = new StandardTileData
{
BackgroundImage = new Uri(imageString, UriKind.Relative)
};
secondaryTile.Update(newTileData);
}

var now = DateTime.Now;
if (now.Day == 25 && now.TimeOfDay.Hours == 9 && (now.TimeOfDay.Minutes > 14 && now.TimeOfDay.Minutes < 46))
{
var toast = new ShellToast { Title = "Xmas Countdown", Content = "Merry Xmas! Thank you for using 'Quick Xmas List' and have a safe holiday!" };
toast.Show();
}
}

关于windows-phone-8 - Windows Phone 8 自定义每小时范围动态磁贴更新频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23290678/

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