我正在尝试扫描两个ibeacon区域并获取锁定屏幕或背景通知。这两个地区目前仅包括一个Estimote信标。我的代码在我的app代理下面,目前我只收到第一个信标的通知,但不是第二个。我正在使用最新的swift 2.2,Xcode 7.3.1以及与最新iOS的iPhone 4s一起使用。 “boplateplate”和“common”的部分代码是故意遗漏的,以缩短这个问题。
导入CoreLocation 导入UIKit
@UIApplicationMain class AppDelegate:UIResponder,UIApplicationDelegate,CLLocationManagerDelegate,ESTBeaconManagerDelegate {
var app: BeacondoApp!
var locationManager: CLLocationManager!
var locationManager2: CLLocationManager!
let beaconManager = ESTBeaconManager()
let beaconManager2 = ESTBeaconManager()
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
ESTConfig.setupAppID("xxxx", andAppToken: "xxxx")
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert, categories: nil))
self.beaconManager.delegate = self
self.beaconManager.requestAlwaysAuthorization()
beaconManager.avoidUnknownStateBeacons = true
self.beaconManager2.delegate = self
self.beaconManager2.requestAlwaysAuthorization()
beaconManager2.avoidUnknownStateBeacons = true
self.beaconManager.startMonitoringForRegion(CLBeaconRegion(
proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!,
major: 28345, minor: 32093, identifier: "S Region"))
self.beaconManager2.startMonitoringForRegion(CLBeaconRegion(
proximityUUID: NSUUID(UUIDString: "C7F8D409-D559-4D48-B251-865941710A5D")!,
major: 35148, minor: 41932, identifier: "P Region"))
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager2 = CLLocationManager()
locationManager2.delegate = self
return true
}
func beaconManager(manager: AnyObject, didEnterRegion region: CLBeaconRegion) {
let notification = UILocalNotification()
notification.alertBody =
"Estimote S Entry Notification"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
print("Estimote S Entry Notification")
}
func beaconManager(manager: AnyObject, didExitRegion region: CLBeaconRegion) {
let notification = UILocalNotification()
notification.alertBody =
"Estimote S Departure Notification"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
print("Estimote S Exit Notification")
}
func beaconManager2(manager: AnyObject, didEnterRegion region: CLBeaconRegion) {
let notification = UILocalNotification()
notification.alertBody =
"Estimote P Entry Notification"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
print("Estimote P Entry Notification")
}
func beaconManager2(manager: AnyObject, didExitRegion region: CLBeaconRegion) {
let notification = UILocalNotification()
notification.alertBody =
"Estimote P Departure Notification"
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
print("Estimote P Exit Notification")
}
}