I'm developing an iOS app using AWS for the first time. Most things are straight forward, but I'm having trouble finding out how to schedule a push notification in the future. I'm currently using AWSSNSPublishInput to send a push immediately, but there doesn't appear to be any way to schedule the notification for some date-time in the future. I would just use UILocalNotification to schedule the future notification, but I need to schedule the notification for a different user.
For example, user A performs an action that user B needs to know about the next day.
Anyone have any ideas?
Amazon Simple Notification Service (SNS) is designed to send notifications immediately. There is no functionality for scheduling notifications in SNS.
Amazon Simple Queue Service (SQS) does have a delay feature, but only up to 15 minutes -- this is useful if you need to do some work before the message is processed, such as copying related data to Amazon S3.
Given that, you need to schedule notification for some future time. you need to implement the logic yourself on server side like database polling after some fixed interval of time OR something like job scheduler.
Related
I need opportunity, run some code at the moment when my app is killed. For example, a user doesn't open my app in the course of week or month.
Some information about working my app.
The User can save settings which contain push notification. These local push notification my app can get every day, but time every day can be different and I want to create local push when my app is closed and doesn't open during some days, weeks or months etc.
I have read about "silent push notification", but it is not fit me because in my app hasn't a server. Also, I have read about "significant location", also it is not fit me. Who knows an alternative way, how its implementation?
Since your goal is to run a local notification some number of days after the app is terminated, one solution is to schedule a local notification when the app enters the background. When the app enters the foreground or if it is restarted, check if enough time has passed or not. If not, delete the most recently scheduled local notification. This way it only triggers if the user doesn't actually use your app for those days (or whatever timeframe your choose).
There is no point to use repeating notifications if the scheduled time is variable. There is also definitely no way to run some code in the background if app is killed, so the only suitable solution would be to use remote push notifications. If you don't want to deal with the trouble of making a push server etc. Firebase might be a good choice: Firebase Cloud Messaging client app on iOS
Is it possible to write an app for iOS that is capable of sending local push notifications to user without a remote server?
For example, if I have a 100% local application, can I make it to slow me a notification, let's say, every day at 10PM? Is it possible to have a background service, or schedule a task of some sort locally in iOS?
All of the tutorials I can find online make use of a remote Push API service. Does it mean, there is no way to have this functionality locally?
Yes, it's called local notifications. Read the notifications for developers guide.
You schedule a user notification request using UNNotificationRequest. Provide a UNCalendarNotificationTrigger or UNTimeIntervalNotificationTrigger object as the trigger, depending if your need.
If you need iOS 9 and below support, there is an analogous UILocalNotification API that is deprecated in iOS 10, but can be used in case backward compatibility is needed.
As I see in many apps when setting user notifications as reminders, it works fine but after a while when the user starts to ignore opening the notification or the app it won't send any more notifications.
Is there a way to disable this behavior and continue sending the notifications even if they don't open the app?
What you are describing sounds like local notifications. These are scheduled in code to go off at a specific time. As far as I know there is no such thing as a recurring local notification. They are "simulated" by creating many single local notifications to begin with.
Edit
As PaulW pointed out. Recurring notifications are possible but are rarely used due to their limitations.
When the app is opened it runs some code to create some more local notifications.
If the app is not opened then the code never runs to create the additional notifications.
So, in this example, it is not iOS stopping the recurring notifications because you haven't opened the app. The notifications stop recurring because you don't open the app and give it the opportunity to create more of them.
So, to answer your question. No. The only way to delay this as long as possible is to create notifications that cover a long time into the future. But then I believe there is a limit to the number of scheduled notifications. (A quick google comes up with a limit of 64 scheduled notifications per app).
Edit you could also use repeating notifications but they are limited to repeat every one unit of time. Once a day, once and hour, once a minute, etc... so you can't do it every two hours.
Alternatively you could use a backend to send remote notifications. These could theoretically recur infinitely because the app is not required to create them. Of course, this assumes you have the infrastructure setup to develop this.
I have an iOS app integrated with Parse.com in which I want to schedule push notifications for certain dates/times. I am storing a push notification time on PFInstallation objects for users who have an upcoming event. I have a scheduled job running on Parse CloudCode that queries for push notification times that need to be sent within the next minute. Is this a good way to architect this? If so, how can I send this push? Parse.Push takes a query for it's where field, but queries only return up to 1000 results which doesn't scale at all for a free app. Thus, I'm trying to use Parse.query.each() which has an unlimited number of results. However, now I'm unsure how to send a push to each installation this way? Do I need to create another query within my each() statement? That seems redundant and inefficient.
(Note that the push notification is a silent notification with the content-available flag set so local notifications are not an option. Also the notifications can be cancelled by the user so scheduling the notification with the CloudCode push schedule API is not an option since those pushes can't be cancelled.)
You say, you store push notifications time on the respective PFInstallation object to circumvent the lack of support for canceling a push notification through Parse, great. We'll call that column ScheduledPushDate; That's the easy part; +1. The part you want to accomplish is actually scheduling a push notification using the given date. Great. Another easy part; +1. The hard part is doing it the way you want; -2. Parse.Push is not only limited by the where field. A lot of variables come into play when sending a push, for example, Parse doesn't even consider any objects that don't have a valid deviceToken so you can omit those objects immediately. The problem your running into is not the push itself, its not how to query for validation, its simply comes down to canceling it. Sure you can always change the date in ScheduledPushDate to be something in the year 2025 or simply negating it altogether, but that doesn't matter because you've already given the notification a scheduled date with the payload. Keeping it simple, and according to your target (you tagged iOS, so this is an answer specifically to client-side resources since you don't want to use local notifications or cloud code) you won't be able to cancel it, because within the guidelines given, you can only construct a push notification so many ways with Parse (client-side, cloud code, dashboard), and as of right now, only one of those options allows a successful means to cancel the process, and it's through the dashboard/console.
Lets say you do it the way you are thinking about:
Execute scheduled job to search for push times that need be fired within the coming minute. What is a "coming minute". Lets say a users time is 11:35.46 (11am35m46sec) and they want to cancel the scheduled notification and cancelled it at that moment, but your job fired at 11:35.00? Realistically, how often will that happen, not many, but it will happen and can happen. You should always code for every circumstance a user will encounter, not just the ones you want to prevent.
Additionally, you would be exhausting almost all of your API request limits if you do have a scaleable app as mentioned.
Lastly, to answer your question, no you don't have to do an innerQuery or additional query within the query.each function, as it's job is to iterate over each result of a query
I would like to know what is the best approach to do if I want to fire notifications for more than one time each day everyday.
I did some research and read that notifications for the next day cannot be fired unless the user opens the app the next day and updated the notification. Is that true? is there anyway I can do it without the need of the user opening the app everyday?
Thank you
You can schedule up to 64 local notifications. There is no limit on the time period; you can schedule them years in advance if you like.
That said, if you need some mechanism to schedule new notifications, even if the app is not running at all (e.g. because the user terminated it), you need a background mode for that. Fetch is probably the way to go here, as it doesn't need a special trigger. You could also send silent push notifications in order to wake the app, make the calculations and schedule the new notifications.