1
下面的代碼對通知正常工作。但是,當我嘗試應用程序時,在近端和遠端之間通知太多。swift和iBeacon在locationManager中發起通知
extension AppDelegate: CLLocationManagerDelegate {
func sendLocalNotificationWithMessage(message: String!) {
let notification:UILocalNotification = UILocalNotification()
notification.alertBody = message
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
func locationManager(manager: CLLocationManager!,
didRangeBeacons beacons: AnyObject[]!,
inRegion region: CLBeaconRegion!) {
NSLog("didRangeBeacons");
var message:String = ""
if(beacons.count > 0) {
let nearestBeacon:CLBeacon = beacons[0] as CLBeacon
switch nearestBeacon.proximity {
case CLProximity.Far:
message = "You are far away from the beacon"
case CLProximity.Near:
message = "You are near the beacon"
case CLProximity.Immediate:
message = "You are in the immediate proximity of the beacon"
case CLProximity.Unknown:
return
}
} else {
message = "No beacons are nearby"
}
NSLog("%@", message)
sendLocalNotificationWithMessage(message)
}
}
它是用一種firedate聲明的方式嗎?喜歡的東西:
localNotification.fireDate = NSDate(timeIntervalSinceNow: 900)
如果我把在 「FUNC sendLocalNotificationWithMessage」,它會firedate所有通知。我不得不以某種方式找到切換之後的一種方式?
或者可能是通知計數器?
謝謝大衛。它運作良好! – Kibo