Hello,
I want to develop an iOS App with Swift capable of monitoring a specific region in backgroud. Specifically, if the didEnterRegion method in triggering I would like to ranging beacons during 10 seconds. It is described and mentioned many times, but I do not khow what is the correct structure of the AppDelegate file.
This is my file:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ESTBeaconManagerDelegate {
var window: UIWindow?
let beaconManager = ESTBeaconManager()
let beaconRegion = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "xxx")!, identifier: "myregion")
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.beaconManager.delegate = self
self.beaconManager.requestAlwaysAuthorization()
UIApplication.sharedApplication().registerUserNotificationSettings(
UIUserNotificationSettings(forTypes: .Alert, categories: nil))
self.beaconManager.startMonitoringForRegion(beaconRegion)
self.beaconManager.requestStateForRegion(beaconRegion)
return true
}
func beaconManager(manager: AnyObject, didDetermineState state: CLRegionState, forRegion region: CLBeaconRegion) {
let notification = UILocalNotification()
if (state == CLRegionState.Inside){
notification.alertBody = "Inside"
}
else if (state == CLRegionState.Outside){
notification.alertBody = "Outside"
}
else if (state == CLRegionState.Unknown){
notification.alertBody = "Unknown"
}
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
func beaconManager(manager: AnyObject, didEnterRegion region: CLBeaconRegion) {
self.beaconManager.startRangingBeaconsInRegion(self.beaconRegion)
let notification = UILocalNotification()
notification.alertBody =
"Alert String"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
func beaconManager(manager: AnyObject, didRangeBeacons beacons: [CLBeacon],
inRegion region: CLBeaconRegion) {
if let nearestBeacon = beacons.first {
let notification = UILocalNotification()
notification.alertBody =
"\(nearestBeacon.proximityUUID.UUIDString), \(nearestBeacon.major), \(nearestBeacon.minor)"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
}
...
}
Where could I call stopRangingBeaconsInRegion? Region monitoring should be stopped while ranging is used?
Could you provide me an example of how to prolongate the 10 seconds available time since a Google backend should be queried?
Thanks in advance.
Regards,
Juan Antonio