I have a task to create an alarm app. I manage to make the alarm sound using Local Notification.
The problem is that I can't make buttons(actions) on the local notification for "Snooze" and "Okay". I also searched how to implement Interactive Local Notification but I can't follow it. What I'm thinking now is to create an alertView with buttons instead of Local Notification in sounding the alarm. Is there a fireDate function in alertView than I can use to make it happen?
No alertview itself dsnt have any firedata property
But you went the right direction as when you want UIInteractive Notification to make a interactive notificaiton without the application being opened.
Here is a link to a much easier Objective C tutorial for Interactive Notifications.
UIAlertView is only used for displaying alerts while the user is using the app. The alert view that's displayed to a user (or, more likely, a banner), is presented by the operating system. You can follow this tutorial on how to create local notifications with actions. Good luck!
for "How to Implement iOS8 Interactive Notification"
you can check this,
link
Here all the steps are mentioned you want to make local notifications...
Related
I have an App built on Swift, I want this App to start every day at some particular time. Logically its like Calendar notification, which gives notification in that particular window whatever we set.
Does is the same scenario is possible with an App in iOS Swift.
What you can probably do is to create a local notification, but this is not opening your app. A local notification is just a way to show a notification on your iPhone and then, if the user taps, it's opening your app.
See more here: https://www.codebeaulieu.com/49/How-to-add-local-notifications-to-your-app
I am not sure what you want to do, you cannot force your application upon the user without the user's consent. What you can do is schedule a local notification so the user knows when to open your app like jomafer proposed already. Also possible is to wake up the app to do stuff in the background:
https://developer.apple.com/library/prerelease/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
For example a silent push notification that will trigger some code, or a scheduled background download.
NONE OF THESE METHODS ARE 100% RELIABLE THOUGH!
When the app is in foreground and it receives a notification, the alert message is shown and it only has an "OK" button, no "Cancel". So the user can't really say: "I want to ignore this message".
Yet, I do need to give users the ability to ignore the notification. They contain a deep link and the user might not want to be taken to another page if she is reading something else.
To do this I implemented a custom alert saying: "Do you want to be taken to this article? Yes / No" and only if "Yes" is chosen the user is taken to the deep link.
The problem is I don't know how to find out when the standard alert has been closed. So I show my custom alert in didReceiveRemoteNotification which results in two alerts overlapping (bad).
What is the recommended solution to give the user a chance to ignore a notification when she is already in the app? Is there a way to customise the default alert message when the app is in foreground?
When your app is in the foreground iOS does not handle the notification. It is directly delivered to your app and your app is handling the notification.
If you have two dialog them most probably your is presenting them both.
This is stated in Local and Push Notification Programming Guide
If the app is running in the foreground when the notification is delivered, the app delegate receives a local or remote notification.
As the doc said, the app delegate will handle the notification.
My app is in background, and the notification alert did show correctly and the badge number was increased by 1.
IF the user taps on the alert everything works fine and the delegate didReceiveLocalNotification is called.
But the user ignored the alert.
After a while when the user open my app again, the only delegate called is didBecomeActive.
How can I do something (show a UIAlertView for example), based on the last ignored alert?
iOS itself doesn't provide any method for that.
But you can simply do that:
While you are registering notification to iOS - write all notification data to a file.
On application start load notification file and all notification that expired (NSDate < now) - those are ignored notifications.
Before doing 2. you need to check if maybe someone came from a notification and delete it from your file.
It's kind of duplicating iOS notification management system which is not allowing to get a list of registered notification unfortunately.
Writing a notification to a file should be easy: it's already implementing NSCoding protocol.
As far as I know, if the notification is ignored, you can't recover it once you open the app again.
You'll need to check the service that pushed that notification to know if there's something new
Unfortunately, there is not a straight forward way to achieve it.
Possible workaround - If the user dismisses/ignored your push notification, your app could take a look at messages on your server and handle it the appropriate way.
I want to display multi-buttons alertview to user everyday twice a day. They can take an action or snooze the action. If they snooze the action then the same alertview will appear again after 10 minutes. Could anyone please tell me what should be the best way to implement this. Thanks.
Local notifications are what you want here. NSTimer only runs while your application is running, which won't (always) be the case.
See this discussion Snooze local Notification for further information.
I am working on a alarm clock app and I've been stuck for the last couple of days. I was hoping you guys could help out.
My question is;
Is there any way to distinguish whether the app was opened through the UILocalNotification alertAction or just opened regularly?
I want to use the UILocalNotification to create a snooze feature, so if the app is opened by the user tapping on the action button on the LocalNotification, a snooze mechanism will launch (but obviously i don't want that to launch if the user regularly opens the app to set the time or something)
Thank you so much for your help!
Yes this is possible as described in the UILocalNotifaction class reference
In the
application:didFinishLaunchingWithOptions:
method the application delegate can
obtain the UILocalNotification object
from the passed-in options dictionary...
Therefore you can check the options dictionary to see if the notification is present. If it is then that's how the app was launched.