应用程序如何在后台检查状态?
How do apps check for status in background?
Uber 等应用通过向 Uber API 发送 GET 请求来检查汽车状态。我假设 Facebook 和电子邮件应用程序在检查通知和新电子邮件时做同样的事情。这在后台如何工作?我如何让这些应用程序检查汽车的状态,或者是否有人给我发了电子邮件,或者是否有东西准备好了?他们使用的是 Background Fetch 还是其他方式?
您可以使用静默远程通知来调用后台进程。根据 Apple 文档,
When a silent notification arrives, iOS wakes up your app in the
background so that you can get new data from your server or do
background information processing. Users aren’t told about the new or
changed information that results from a silent notification, but they
can find out about it the next time they open your app.
To support silent remote notifications, add the remote-notification
value to the UIBackgroundModes array in your Info.plist file. To learn
more about this array, see UIBackgroundModes.
您可以检查您的应用程序是否处于后台模式,然后您可以调用后台进程的方法。
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
//call your background methods.
}
Uber 等应用通过向 Uber API 发送 GET 请求来检查汽车状态。我假设 Facebook 和电子邮件应用程序在检查通知和新电子邮件时做同样的事情。这在后台如何工作?我如何让这些应用程序检查汽车的状态,或者是否有人给我发了电子邮件,或者是否有东西准备好了?他们使用的是 Background Fetch 还是其他方式?
您可以使用静默远程通知来调用后台进程。根据 Apple 文档,
When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.
To support silent remote notifications, add the remote-notification value to the UIBackgroundModes array in your Info.plist file. To learn more about this array, see UIBackgroundModes.
您可以检查您的应用程序是否处于后台模式,然后您可以调用后台进程的方法。
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
//call your background methods.
}