繁体   English   中英

如何限制iOS / Swift3中来自EstimoteSDK的多个通知?

[英]How to restrict multiple notification from EstimoteSDK in iOS / Swift3?

我实现了Estimote SDK,并添加了信标测距/扫描委托方法。 现在,我想在设备仅进入信标区域时触发本地通知。 在这里,我面临本地通知问题。 当我进入信标区域时,我会收到通知,这很好,但它会在随机间隔后重复多次。 我不止一次收到本地通知。

第二件事是,是否有任何方法可以从通知区域清除触发的通知。 因为我想一次只显示1条通知。 因此,当它触发本地通知时,应该从通知区域清除存在的通知(如果已有的话)。

我尝试使用cancelLocalNotificationcancelAllLocalNotifications,但未删除通知。

这是我的代码实现:

    beaconRegion.notifyOnEntry = true
    beaconRegion.notifyOnExit = true
    self.beaconManager.delegate = self
    self.beaconManager.requestAlwaysAuthorization()
    self.beaconManager.startMonitoring(for: beaconRegion)

func beaconManager(_ manager: Any, didEnter region: CLBeaconRegion) {
    if isAuthenticated == nil {
        return
    }

    let notification = UILocalNotification()
    notification.alertBody = "You are in beacon range."
    notification.fireDate = Date.init(timeIntervalSinceNow: 2)
    notification.userInfo = ["enterInBeaconRange":true]
    UIApplication.shared.presentLocalNotificationNow(notification)

}

现在,如果我在通知前设置“ cancelAllLocalNotifications”方法,则不会从通知中心清除所有先前的通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM