Enter the iBeacon realm with the app in the background and request the URL without notice.

I searched SO and Google many times to try and get an answer for this, but I could not put together all the pieces of the puzzle so that any help / pointers would be good.

I would like to create an application that validates a web service when it enters the iBeacon realm. A simple use case might be the following:

  • user enters iBeacon-equipped store with app in background

  • instead of notifying the user, the application makes a request to the web server to check if the user ID is a member (the application was granted permission to send the user ID to the server by the user).

3a. server sends a true response

4a. the app sends "We have special ads for members today" to lock the screen.

OR

3b. the server sends a false response

4b. the application remains silent (without notifying the user)

FYI, this answer seems to suggest sending a URL request in the background: Running URL requests in the background

+4
source share
2 answers

You pretty much determined everything you need to do.

When you call the method CLLocationManagerDelegate didEnterRegion:, you can run the background job and then run the network request. After you receive a response, you can send a local notification, if necessary, and then complete the background task.

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    // If not already performing a background task for this region...

    UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
        self.backgroundTask = UIBackgroundTaskInvalid;
    }];

    // perform network request - if successful, display notification. when finished, end background task
}

, - didEnterRegion:. - API, , didEnterRegion:.

+5

All Articles