我的应用有时会忘记
region.notifyEntryStateOnDisplay = false
我在MainView控制器中设置了一个CLBeacon区域:
let locationManager = CLLocationManager()
var region:CLBeaconRegion!
override func viewDidLoad() {
super.viewDidLoad()
region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: uuidString!)!, major: majorvar, minor: minorvar, identifier: "Beacon")
// 2. setup locationManager
locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// 4. setup test data
setupData()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = false
region.notifyOnEntry = true
region.notifyOnExit = true
region.notifyEntryStateOnDisplay = false
// Request authorisation to track location
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedAlways) {
locationManager.requestAlwaysAuthorization()
}
if (CLLocationManager .isMonitoringAvailableForClass(CLBeaconRegion))
{
print("OK")
}
else {
print("Problem")
}
locationManager.startMonitoringForRegion(region)
locationManager.startRangingBeaconsInRegion(region)
locationManager.startUpdatingLocation()
}
我在didEnterRegion
和didExit
地区拨打推送通知。它工作正常。然而,经过一段时间后,应用程序似乎忘记了notifyEntryStateOnDisplay=false
。因为当我在灯塔区域时,它开始触发推送通知进入和退出每分钟左右。
是不是因为我在视图控制器中设置了区域而不是在app委托中?有什么想法吗?
非常感谢 斯蒂芬