[英]iOS: How to expire a local notification with a region trigger?
我有一個本地地理圍欄通知,使用以下代碼進行設置:
func startMonitoring(annotation:MKAnnotation) {
let region = CLCircularRegion(center: annotation.coordinate, radius: 10.0, identifier: "randomID")
region.notifyOnExit = false
let notification = UILocalNotification()
notification.region = region
notification.alertBody = "You got it!"
notification.category = self.notificationCategory
notification.soundName = "my_sound.wav"
notification.userInfo = ["ID": "randomID"]
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
這很有效,但是用戶必須在一定時限內到達該區域才能使通知的動作可用。 如果時間限制已經過去,我怎么能不通知?
我目前只對用戶的位置進行“WhenInUse”授權,並希望保持這種方式。
您最好使用CLLocationManager手動監視CLCircularRegion,並在通知您的應用程序用戶已進入該區域時,檢查它是否在時間限制內並手動發布UILocalNotification。
請參閱此處Using Regions to Monitor Boundary Crossings
: https : //developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html
您可以使用setminimumbackgroundfetchinterval
設置后台提取,並在計划到期時取消已安排的通知。
它不是100%可靠,因為你無法控制確切的時間,但總比沒有好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.