2017-01-09 4 views
0

J'ai implémenté Estimote SDK et ajouté la méthode de délégation de balise/balayage. Maintenant, je veux déclencher une notification locale lorsque l'appareil vient d'entrer dans la région de la balise. Ici, je suis confronté à un problème avec la notification locale. Lorsque j'entre dans la zone balise, je reçois une notification qui est correcte mais qui se répète plusieurs fois après un intervalle aléatoire. Je reçois notification locale plus d'une fois.Comment limiter la notification multiple de EstimoteSDK dans iOS/Swift3?

La deuxième chose est, Y at-il un moyen d'effacer la notification déclenchée de la zone de notification. Parce que je veux montrer seulement 1 notification à la fois. Ainsi, quand il déclenche la notification locale, il devrait effacer la notification existante de la zone de notification, s'il y en a déjà.

J'ai essayé avec cancelLocalNotification et cancelAllLocalNotifications mais les notifications ne sont pas supprimés.

+0

Veuillez partager votre code pour voir ce que vous pourriez faire de mal. –

Répondre

0

Ceci est mon mise en œuvre du 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) 

} 

maintenant Si je suis la mise en méthode « cancelAllLocalNotifications » avant la notification, il n'effacement de toute notification préalable du centre de notification.

+0

Vous ne pouvez pas annuler les notifications déjà déclenchées. Vous pouvez le faire pour les programmés. –

+0

Est-ce possible avec le nouveau framework ** UNUserNotificationCenter **? –

+0

Désolé pour la réponse tardive, vous pouvez utiliser 'removeAllDeliveredNotification()' pour effacer la notification précédente. Le meilleur moyen est d'avoir l'identifiant pour la notification délivrée, puis 'removeDeliveredNotifications (" PREVIOUSLY_DEVLIVERED_NOTIFICATION_ID ")'. –