Can a Local Notification triggering be detected without tapping on the notification? - ios

My app starts a timer when the local notification based on date is triggered using UNUserNotificationCenterDelegate::didReceive delegate.
But what if the app is already opened when notification is triggered, I want my timer to start automatically at that point, without tapping on the notification.
Is this possible ?
e.g:
I want to set a notification for 3 pm, at that point start a 30 min timer (this should start at exactly 3 pm), that will expire at 3:30 pm.
What if the user taps on notification 10 mins later, at 3:10 pm...the timer will expire at 3:40.
That is why I want to start the timer when notification is triggered, not when the user taps on it.

Method userNotificationCenter(_:willPresent:withCompletionHandler:) will be called when a notification is delivered to a foreground app.
Source : Link

Use this method for using your timer concept
application:didReceiveLocalNotification:
But yes when your app is in background state, and if local notification come, you won't receive any method call.

Related

Local Notification in iOS(Objective C)

I have scheduled the local notification on tomorrow 10 AM and i switched off the mobile and then turn on my mobile day after tomorrow.At this time the notification is not receiving.But I can able to receive the notification, once i meeting the scheduled date and time.So this is possible, to get the notification once crossed the scheduled date and time in iOS?
Could you please rephrase your question?
From what I understand you say that your local notification is not delivered if the device was not turned on at the scheduled time.
In general, your local notifications are not handled by your app. When you register a local notifiction, iOS is responsible for delivering it. This also means that your app does not have to be running when your local notification is scheduled to be delivered.
When your local notification was meant to be delivered at 10 AM, but your device was turned off from 9:50 to 10:10 AM, your local notification will be lost!
Your app should not rely on delivering that local notification. Your only way of knowing whether a user received your local notification is when he opens your app by clicking on the notification or using one of its actions. Your app will then be called by application:didReceiveLocalNotification when it is in the background, or regular by application:didFinishLaunchingWithOptions: when it was killed before.
TL;DR: You should not care whether a user received a local notification, as there is no way to make sure he receives it under certain conditions.

Repeat notification with different time

I have created a local notification on 10:00 AM and I want to repeat the notification based on a calculation for the next time when the first notification triggered.
So how can I listen to the notification trigger to create the next notification?
Note: I have used didRecieve notification delegate but it works only if the app in the foreground I want the same thing for the background.
time interval trigger would do it.
https://developer.apple.com/documentation/usernotifications/untimeintervalnotificationtrigger
Use a UNTimeIntervalNotificationTrigger object for local notifications that you want delivered at a time relative to the current time. You specify the number of seconds that must elapse before the notification fires. You can also set up the trigger to repeat at the specified interval.

UILocalNotifications algorithm

I have a problem scheduling UILocalNotifications.
My case is this: when user selects motivation category there is a dialog screen where he selects how many times in a day, week, month, motivation message should be presented to him. Then he selects time period: a day, week or a month. A motivation category has messages, and every category has different number of messages.
So my question is: how should i schedule those notifications? Main problem i think is that there can be more than one category. Can someone tell me how to do this?
I know that i cant schedule more than 64 notifications, so i cant schedule all notifications when category is selected. And i know i could reschedule notifications in
application:didFinishLaunchingWithOptions:
or
application:didReceiveLocalNotification:
I hope i have been clear about my problem.
First write a function that manages the local notifications
that is it has to check if there are 64 notifications scheduled if not then you may add some notification.(you have to handle DB part well for example setting the flags correctly)
Call the function in application:didFinishLaunchingWithOptions: just in case some notifications are expired or missed
You have to call the function in all the places where local notification is handled.
The user taps a custom action button in an iOS 8 notification.
In this case, iOS calls
application:handleActionWithIdentifier:forLocalNotification:completionHandler:
You also get the local notification object, so that you can retrieve any information you need to handle the action.
The user taps the default button in the alert or taps the app icon.
The system launches the app and the app calls its delegate’s method, passing in the local notification object
application:didFinishLaunchingWithOptions:
The notification is delivered when the app is running in the foreground.
The app calls the UIApplicationDelegate method
application:didReceiveLocalNotification:
Reference1:
Reference2:
I hope this helps.
If it doesn't cover your problem feel free to ask doubts
It works as pool when you utilized all your available notifications then you need to reschedule the free notifications in
application:didReceiveLocalNotification: but every time you are gonna reschedule you can find next notification to user that could be in today, tomorrow. Whenever you are in application:didReceiveLocalNotification: findout when to notify next and schedule.

Show Push Notification for time which user has set

I have implemented the Push Notification Successfully in the application, and I need to provide an option to user Where they can set the time for not showing receiving notification. all other time they can receive. I am storing the detail of their Do Not Disturb time in the database in the backend. I just want to check when the notification is fired. the current device time of user. and if that falls under their DND time. Notification is not to be shown and event the sound is not to be shown. Even in the Notification Section.
Any Help will be appreciated.
You can get the the timezone of the device along with the schedule. Depends on the time you need to fire the notification from your server.
i.e, once you fired the notification from your server you can't stop it from showing

Cancelling local notification on specified date

I have problem with even inventing the posible solution for this problem.
My app needs to crate some objects of UILocalNotification with interval but if I set interval to be NSMinuteCalendarUnit if will bother me every minute until I cancel this notification in UIApplication or crash my phone with hammer...
But I'm setting in my app an end date for my project and I want those notification to work only to a specified date. Someone told me to check it when the app launches (not a problem but what if I set this notification to be fired every minute and I won't close my app during this time?). I need something independent and I want to know how to do this.. Any ideas?
You could check if you need to cancel the local notification in receiving one when you app is running and on the start up of you app.
When your app is running in the foreground and a local notification is fired for you app the application:didReceiveLocalNotification: is called on your App delegate.
There is not end date for local notifications thus the only way you can cancel then is from you app when it is running.

Resources