Я использую маяки Bluecats для своего приложения. Я хочу определить, входит ли пользователь в область маяка, когда пользовательское приложение не запущено, я хочу показать локальное уведомление о том, что пользователь вошел в область маяка
Вот мой код: Класс делегата приложения
var beaconManager = BCBeaconManager()
var beacon_region: BCBeaconRegion!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
beaconManager.delegate = self
self.requestAuthorizationForLocalNotifications()
BlueCatsSDK.startPurring(withAppToken: "7d17d7cb-8a26-4b8b-999f-9b031deab7a5", completion: { (BCStatus) -> Void in
let appTokenVerificationStatus: BCAppTokenVerificationStatus = BlueCatsSDK.appTokenVerificationStatus()
if (appTokenVerificationStatus == .notProvided || appTokenVerificationStatus == .invalid){
}
if (!BlueCatsSDK.isLocationAuthorized()){
BlueCatsSDK.requestAlwaysLocationAuthorization()
}
if (!BlueCatsSDK.isNetworkReachable()){
}
if (!BlueCatsSDK.isBluetoothEnabled()){
let alert = UIAlertController(title: "Turn On Bluetooth", message: "This App requires that Bluetooth is enabled to process your orders", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Don’t Allow", style: UIAlertAction.Style.cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Allow", style: UIAlertAction.Style.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
}
})
self.beaconManager.startMonitoringBeaconRegion(beacon_region)
return true
}
// On Exit
func beaconManager(_ beaconManager: BCBeaconManager!, didExitSite site: BCSite!) {
PresentNotifications(title: "You exited the region")
}
// On Enter
func beaconManager(_ beaconManager: BCBeaconManager!, didEnter site: BCSite!) {
PresentNotifications(title: "You Entered the region")
}
func beaconManager(_ beaconManager: BCBeaconManager!, didDetermineState state: BCSiteState, for site: BCSite!) {
if state == BCSiteState.inside{
PresentNotifications(title: "You are inside the region")
}
else if state == BCSiteState.outside{
PresentNotifications(title: "You are outside the region")
}
else{
return
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
self.beaconManager.startMonitoringBeaconRegion(beacon_region)
}