0

I've got an app which can tell whether or not an iBeacon is in range, does anybody know how I can make the iPhone notify the user when an iBeacon is in range with a push notification even if the phone is sleeping?

edit: My problem is different to this question as I don't know how to generate push notifications. Much less do all of this when the app is inactive.

Community
  • 1
  • 1
Matt Spoon
  • 2,580
  • 5
  • 23
  • 40
  • 1
    possible duplicate of [iBeacon Notification when the app is not running](http://stackoverflow.com/questions/19127282/ibeacon-notification-when-the-app-is-not-running) – Leo Jun 08 '15 at 07:16

1 Answers1

0

Typically, beacon apps use Local Notifications not Remote Notifications to alert users when beacons are nearby. Both look the same to the end user but local notifications are initiated from code running on the phone and remote notifications are pushed from a server. You can read about the differences here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

You can send a local notification from the didEnterRegion callback like this:

UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.alertBody = @"I see a beacon";
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];

You also need to request permission to send local notifications in your didFinishLaunchingWithOptions method:

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
  [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil]];
}
davidgyoung
  • 59,109
  • 12
  • 105
  • 181