0

I have a local notification set to repeat every 1 minute. If the user does not interact with any of the notifications after 2 hours (or 120 repetitions), I would like to stop delivering the notification.

PLEASE NOTE: I would like to do this without scheduling individual notifications for every minute as Apple has a limit of 64.

Jared
  • 793
  • 6
  • 16
  • Hello @jared, You can remove notification by using their identifier. you can use time to set that notification and check weather notification is tapped or any other event is done using that notification. also check current time and set time for notification if time difference is 2 hours then re-schedual notification after 1 day. – Hiren Rathod Apr 10 '18 at 05:31
  • Thank you for your response Hiren. Can I do this if the user does not interact with the notification? Essentially the app would be closed or in the background sending notifications. How would I cancel the notification after two hours if the user does not interact with the notification? – Jared Apr 10 '18 at 17:27
  • Yes @jarad, every time when you get notification at that time did-receive notification call in background weather app in terminated or in background. in that delegate method you can check using stored time in userdefaults and remove if time diffrence is 2 hours. – Hiren Rathod Apr 11 '18 at 07:58
  • @HirenRathod Are you referring to the delegate methods `application(_:didReceive:)` (deprecated) and `userNotificationCenter(_:willPresent:withCompletionHandler:)`? Both of these methods state in the documentation that they only trigger while the app is in the foreground. Are you referring to another delegate method? https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622930-application?language=objc https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter – Jared Apr 11 '18 at 15:24
  • @jarad, I have user "userNotificationCenter(_:willPresent:withCompletionHandler:)" delegate method. it will call whiile notification cames. – Hiren Rathod Apr 12 '18 at 06:37
  • Hmmm, thank you for help, but unfortunately, this doesn't work for me when the application is in the background, only the foreground. – Jared Apr 13 '18 at 18:34
  • @jared Have you found a solution on how to stop notifications? I would be pretty interested how to achieve this too! – Hans Bondoka Sep 13 '19 at 20:31

0 Answers0