Search code examples
iosapple-push-notificationsibeacon

local notification with API call


I got an application where I have some local notification. And they work fine with trigger and all that, even when the app is in the background.

But right now I just have some static text in that notification, I then click on it and it open on the App and it makes api call to server where I then get the name back I need and content.

What I would like to do is that when the notification get triggered it make the Api call and get the content. So my notification instead can be write something like "This is X" and X get replaced with the content from the server.

It is with iBeacons I'm working with, so it is when I get near a iBeacon I get a notification.


Solution

  • So I assume that you have some iBeacon manager which calls didRangeBeacons:

    func locationManager(manager: CLLocationManager, didRangeBeacons clBeacons: [AnyObject], inRegion region: CLBeaconRegion) {
        // schedule local notification
    }
    

    and you schedule a local notification in there. All you need to do is to make a server call first and schedule local notification once it's finished.

    You need to remember, that your application can be in the background (or even killed) when the user enters the beacon region so you need to start ranging when didEnterRegion gets called:

    func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
        // start ranging for beacons
    }