Iphone后台任务,即使在应用程序关闭后



我一直在阅读文档,但没有意义。所以我决定问这个问题。Iphone上的应用程序就像有闹钟的时钟。当我设置闹钟并关闭应用程序时,即使我关闭了应用程序,应用程序仍会在凌晨4:30通知我。现在我的理解是,为了让这样的东西发挥作用,你必须让它一直在后台运行。这是没有意义的部分。如果我双击主页按钮,然后向上滑动以删除该应用程序,从而完全关闭了该应用程序。如果不再在后台运行,该应用程序如何监控时间?苹果表示他们有5个州
1-未运行
2-非活动
3-活动
4-背景
5-悬浮

以上内容的解释位于此处我可以想象,当我关闭一个应用程序时,状态没有运行。然而,
报警应用程序仍然打开。如何打开?这让我很难过。有没有一种只有本机应用程序才能拥有的特殊状态?
如有任何信息或进一步了解,我们将不胜感激。

Miguel的情况并非如此。您正在寻找的是:

https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html

使用UILocalNotifications,您的应用程序根本不必跟踪时间。它会安排通知,操作系统会跟踪它。我已经构建了很多带有通知/警报的应用程序。我希望这会有所帮助。

您可以使用本地通知。

当您之前添加的本地通知触发时,iOS将通知用户。[iOS将添加通知,但您的应用程序根本不会运行当用户点击通知时,应用程序将打开。]

- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.repeatInterval = NSDayCalendarUnit;
[notification setAlertBody:@"Hello world"];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]];
[notification setTimeZone:[NSTimeZone  defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];
}

教程:http://www.appcoda.com/ios-programming-local-notification-tutorial/http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/

概念指南:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

最新更新