[英]iOS Local Notification Trigger Handling
我目前正在制作一個應用程序,該應用程序會計算步行步驟,並核對目標並在遇到問題時發布本地通知。 我已經設置了本地通知,但是我希望此刻僅觸發一次。 我通過dispatch_once_t得到了這個工作:
if stepsData >= stepsGoalData {
let localNotification = UILocalNotification()
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
localNotification.fireDate = NSDate()
localNotification.alertBody = "Acheived"
localNotification.soundName = UILocalNotificationDefaultSoundName
}
但是,如果用戶增加了stepsGoalData,則當前代碼不會觸發通知。 有人可以為我提供處理此案的想法嗎? 謝謝!
因此,您實際上應該只更改檢查是否通知的檢查,以便它不僅考慮計數,還考慮指示是否已發出通知的標志。 這可以是在stepsGoalData
旁邊定義為簡單Bool
的var。
現在,您的支票將是:
if stepsData >= stepsGoalData && !hasNotified {
hasNotified = true
...
並且,當您將stepsGoalData
設置為新的目標值時,您還設置了hasNotified = false
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.