如何设置UNLocationNotificationTrigger的到期日期

时间:2017-01-25 14:15:31

标签: swift3 cllocation unusernotificationcenter

我正在设置一个UNLocationNotificationTrigger以在特定位置触发。我希望仅在用户在特定日期之前输入位置时才显示通知。如果他以后进入该位置,则不应触发通知。

是否可以为UNLocationNotificationTrigger设置到期日期?

1 个答案:

答案 0 :(得分:0)

本地通知没有到期日。为了实现您的方案,您可以做的是在检查日期之前的某个时间安排计时器,以检查用户是否已输入该位置。如果有,请安排通知。如果他没有安排它。可以按如下方式安排计时器:

let timer = Timer(fire: your-date, interval: 0, repeats: false, block: {(timer: Timer) -> Void in
                // check for location and schedule accordingly
            })
RunLoop.current.add(timer, forMode: .commonModes)

确保您在计时器中设置的日期早于通知日期,以便有时间安排通知并显示通知。

希望这会有所帮助。 :)

相关问题