Nathan McKaskle
Nathan McKaskle

Reputation: 3063

How do apps check for status in background?

Apps like Uber check for the car's status by sending GET requests to Uber's API. I assume Facebook and E-mail apps do the same thing when checking for notifications and new e-mails. How does this work in the background? How do I keep these apps checking for the status of the car, or whether someone sent me an e-mail, or whether something is ready? Are they using Background Fetch or something else?

Upvotes: 0

Views: 372

Answers (1)

Fawad Masud
Fawad Masud

Reputation: 12344

You can use silent remote notifications to invoke background processes. According to Apple documentation,

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.

For details https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

You can check if your application is in background mode or not and then you can call methods for background processes.

if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
    //call your background methods.
}

Upvotes: 2

Related Questions