我想启动一项服务,偶尔在所有平台上检查是否有通知出现。有没有连接所有平台的nuget或者一些例子?
您可以使用Device.StartTimer(TimeSpan minutes)
方法启动一个后台任务,该任务将在给定的时间跨度后重复。这是一个代码示例:
var minutes = TimeSpan.FromMinutes (3);
Device.StartTimer (minutes, () => {
// call your method to check for notifications here
// Returning true means you want to repeat this timer
return true;
});
它包含在 Xamarin Forms 中,因此您不需要任何特定于平台的逻辑。
http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.Device.StartTimer(System.TimeSpan%2CSystem.Func%7BSystem.Boolean%7D) http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.Device.StartTimer(System.TimeSpan%2CSystem.Func%7BSystem.Boolean%7D)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)