toast toast - 23 days ago 8
Objective-C Question

Checking for server side app notifications in the background, in Swift

When I say notifications, I mean custom app notifications, so not iOS notifications. Notifications like Facebook's notification tab. Basically I want to check if a user has new friend requests, or if someone has commented on their posts, then load this data into a TableView which is displayed in my Notifications tab.

I wondering how I go about continually checking for these notifications from my server. Obviously I shouldn't check on a single tab bar's view controller, such as the NotificationsViewController. So I'm thinking should this type of functionality be performed in the AppDelegate?

And how do I seamlessly perform a request in the background, then have my Notifications tab catch the response, and parse it, so I can display a notifications badge. A snippet of Swift code, and where I should be placing it would be really helpful!

Thank you.

Answer

You can use silent push notification, it will inform your app that something new happened without showing the alert to user (send it from your server), perform repeated request in background is very energy consuming and does not advised, also it wont work if your app is not openning. To store it then can just use NSUserDefault or CoreData