4

My app receives silent push notifications via FCM, as I see in the logging the are received and handled. What my app then does is decide to some logic if a notification is shown to the user or not. This sometimes works, sometimes doesn't. It seems to me as if it works first and then suddenly stops working, so I'm guessing if it may be a throttling problem?

I do schedule 5 notifications 30 seconds apart - so the user does not miss the notification:

    for i in 0...5 {
        let notification = UNMutableNotificationContent()
        notification.title = NSLocalizedString("bed_wet", comment: "")
        notification.subtitle = device.lookAfterPatientString
        notification.sound = UNNotificationSound(named: "alarm.mp3")
        notification.categoryIdentifier = Notification.Category.alarm
        notification.userInfo = ["identifier": device.id]

        let timeInterval = max(1, delaySeconds) + i * 30
        let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(timeInterval), repeats: false)
        let request = UNNotificationRequest(identifier: UUID.init().uuidString, content: notification, trigger: notificationTrigger)

        UNUserNotificationCenter.current().add(request) { error in
            ...
        }
    }

can this loop be the problem?

Dimple
  • 788
  • 1
  • 11
  • 27
swalkner
  • 16,679
  • 31
  • 123
  • 210
  • Print out the timeintervals. Doesn't seem to me there's a throttling for 30 secs intervals. – Gal Oct 04 '18 at 10:09
  • the scheduling happens, that's for sure - it just seems as if the notifications are never shown... – swalkner Oct 04 '18 at 10:43
  • I found this: https://stackoverflow.com/a/47319860/978133 but not sure it answers you... – Gal Oct 04 '18 at 12:01
  • unfortunately not, I never schedule more than 64 at a time – swalkner Oct 04 '18 at 12:03
  • 1
    Could you show more code as there might be an issue elsewhere – AD Progress Oct 11 '18 at 10:49
  • Unrelated: You code loops 6 times and not 5 – ielyamani Oct 12 '18 at 12:05
  • `UUID.init().uuidString` is not guarenteed to be unique between launches, so whenever you create a request you're not guraenteed to have a unique request. So if you try to add a new request with an old identifier, it is just going to update the notification, and not add a new one. – ielyamani Oct 12 '18 at 12:10

1 Answers1

1

Try it with dispatch_async, Several code that not blocking main thread maybe called and some times not called.

The second problem is maybe iOS have logic that prevent an app to spam the phone. Have u seen instagram notification limited from maybe hundred to only several notification.

Thanks

antonio yaphiar
  • 450
  • 3
  • 9