Bhadresh Radadiya
Bhadresh Radadiya

Reputation: 649

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

I implemented Estimote SDK and added beacon ranging/scanning delegate method. Now, I want to trigger local notification when device just enter in beacon region. Here I'm facing problem with local notification. When I enter in beacon region, I'm getting notification which is fine but it repeats multiple times after random interval. I'm getting local notification more than once.

Second thing is, Is there any way to clear triggered notification from notification area. Because I want to show only 1 notification at a time. So, When it triggers local notification, It should clear exist notification from notification area, if there is any already.

I tried with cancelLocalNotification and cancelAllLocalNotifications but notifications are not being removed.

Upvotes: 0

Views: 112

Answers (1)

Bhadresh Radadiya
Bhadresh Radadiya

Reputation: 649

This is my implementation of code:

    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)

}

Now If I'm setting "cancelAllLocalNotifications" method before notification, it's not clearing all previous notification from notification centre.

Upvotes: 0

Related Questions