|
I am designing an application and I send a push notification payload to iOS app everyday at midnight. The payload contains 3-4 different times which I want to use as 'triggers' for 3-4 different local notifications, being fired throughout the day. Is there a way to silent the remote notification completely, and then use the remote notification's payload to parse that JSON and schedule a few local notifications from the payload data ? |
|
Yes this behaviour is supported by iOS and you dont even need user's permission to receive silent notification - https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app |
|
@nemecek-filip Thanks for sharing the link. An additional query I have is that it says "You have 30 seconds to process the payload.... after that serviceExtensionTimeWillExpire() is called". My end-goal is: Once I receive the paylaod from my server, the payload has, say, 6 different times for that day. So that means I need to send local notifications 6 times in that day. Now I need to process the payload, parse the JSON, extract the time and schedule 6 local notifications. What if I am not able to do that in 30 seconds ? Is there a way to increase this 30 seconds limit? If not, is there a workaround for that ? Potentially, I think storing the remote payload in a JSON file would help, maybe ? |
|
30 seconds is a lot of time. I would be surprised if your JSON parsing and notifications scheduling took more than 1 second |
|
Thanks a lot for your help! I will try it out and see how it works out. One last thing, is it possible to perform some sort of check before actually displaying a scheduled local notification? Like if a user has a "Goal" that starts at 10:30 AM (local notification scheduled for 10:25 AM). But the user actually completes that "Goal" at 10 AM, then I don't want to show the notification at 10:25 AM obviously. One way is to use I found only 2 other functions dealing with notification displays:
Clearly, none of these help me. Any ideas? Do I really have only |
|
You can remove specific scheduled notifications based on their identifier. So when user completes the goal you would use notifications center to remove just that one specific notification from the queue. |
|
Ah, got it! Thanks a lot for the help. Really appreciate it. I was kinda lost for a few days now but now eveything seems finally clear! |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.