iPhone local notification in different application states - iphone

I'm using local notification in my app but have a problem handling them correctly.
When app is running, and active, in didReceiveLocalNotification I can fetch user settings from NSUserDefaults and handle the repeating notification, and cancel it if fire date isn't the day it should fire, or show an alert if it's correct date.
However, when app is running, but inactive, the notification will fire although it shouldn't.
Same thing when app is not running, the notification will fire although it shouldn't.
Question
When app is not running, and when app is inactive, how can I access NSUserDefaults and cancel the notification before the alert show up?
Edited answer
The reason I had to ask this was because of bad app design and logic. I tried to set repeating local notification no matter what settings user has set and access NSUserDefaults in it although I should have access user settings first in app itself and then set notifications accordingly.

You can't. a UILocalNotification is handled by iOS and not your app.
Only when your app is active the notification get directly pushed to you app.
In all other cases the os will just show the notification.

Related

Handling Local Notification in objective C

I am working on an iphone app where I store all the local(and push) notifications for my app. There will be a screen on app which shows all the notifications generated by the app. My question is that can an iphone app know when a local notification for that app is shown. for example, suppose that a local notification is shown, but the user simply ignores that notification, and does not tap on it, so in this situation, can my app somehow find out if the local notification was shown and do some processing on it(for example, store the notification data in sqlite database).
I have tried both "didFinishlaunchingWithOptions" and "didReceiveLocalNotificatios", but from my understanding, they are invoked when a user laucnhes app by tapping on the notifiaction, is there a method by which I can have the notification data even when user does not tap on the notification.
tldr; can an iphone app handle(process) local notifications even when user does not launch app by tapping the notification.
No, your app wan't get any notification whcih user has ignored. Your app will notified only when user presses view or tap on that notification.

How to bring iphone app from background to foreground without user interaction when push notification comes in objective c? [duplicate]

This question already has answers here:
Relaunch iOS app without user interface when application in background?
(4 answers)
Closed 10 years ago.
Please suggest me objective c code for bringing the app from background to foreground without any user interaction when push notification comes.
Unfortunately it is not possible as Notification come and your app started automatically even without user interaction.
As Push Notification comes it Handles by OS.
If a notification for an application arrives when that application is not running, the device alerts the user that the application has data waiting for it.
Then It means user have to interact with the Device.
From The Apple Doc.
When the operating system delivers push notification (iOS or OS X) and the target application is not running in the foreground, it presents the notification (alert, icon badge number, sound). If there is a notification alert and the user taps or clicks the action button (or moves the action slider), the application launches and calls a method to pass in the local-notification object or remote-notification payload. If the application is running in the foreground when the notification is delivered, the application delegate receives a local or push notification.
That's All.
I hope it clears to you.
I dont think its possible. Once push notification came, the os itself handles and show notification if it is enabled for your app. Then from the notification, if you are going to app, then didReceiveRemotenotification callback will be fired.
Thanks.
It's possible but it would require a jailbroken iPhone and hook the push notification receiver to launch your app when the notification is received.
If you aim for App Store you can't.

phonegap ios) is it possible distinguish push notification that user clicked?

I am using phonegap push notification plugin and all seems work fine. push comes without any problem.
But the problem is there is nothing I can do when app is back-grounded.
multiple push notifications can arrive when app is backgrounded. I can not expect which push
notification user going to click. Whatever notification user clicks, app will be resumed without
information of user selection. I have to trigger different events depanding on what nofitication
user selected. I need to know what notification user selected when app is resumed but don't
know how to... seems very tricky problem. is there anybody had same problem?
how did you guys handle this problem?
any help will be appriciated.
never mind...
I thought window.plugins.pushNotifiction.getPendingNotification would return all pending
notifications which arrived while app is background.
But getPendingNotification function only returns the notification that user selected on
notification center or mobile screen.
well... seems nice..
you can`t get all notification information which fire during application is off or app. is in background but, you can fetch user info shortly receive notification in native iOS app.
please follow this application:didFinishLaunchingWithOptions.
At first call of launch you can check for options and retrive the user-info.
for more info refer above link.

push notifications: sounds and badges

I'm working with push notifications and i have a doubt: if in my script (server-side) there are badge and sound, but the user set sounds and badges off... what happens?
I mean: i need to register in my database every setting for every token, or i send the notification and the iPhone does all the work? :)
Thanks!
You don't need to worry about the user settings. The user will receive the alerts he allowed. So if he doesn't want to have the sound and he switch it off. You can still send it and he just receive the alert and or badge...
If the user switches off a particular notification type in user settings, such notifications are not received by the application. For example:- lets say I registered for sound and badge notifications but I disabled the badge notifications in user settings, the application will only receive the sound notifications from now until I enable the badge notifications in user settings or register again for alter notifications too. Re-registering for badge notifications wont enable the badge notifications since they are disbled in user settings.

How to retain access to the UILocalNotification if the event message was initially ignored

I have a UILocalNotification that fires on a recurring schedule. The purpose that the notification fulfills is to just simply remind the user to do something. When the notification fires, they can enter into the app and another alert pops up and asks them if they complete the task, and the app tracks accordingly.
If the user is using their phone, the notification fires, and the app switches great, and the user input is recorded. If they are using the app at the time the notification fires, everything works great. If they aren't using their phone, the notification wakes the phone up, and has an option to "Slide to view" whereupon the app comes up and the alert pops up great and the input is recorded.
The problem is when the user isn't using their phone, and the user DOESN'T slide to view during the few second window that the alert wakes up the phone, when the user wakes up the device later on, the alert window is still there, letting the user know that something happened, but the "Slide to view" option is replaced with the standard "Slide to unlock" and when the phone is unlocked, the ability to go into the app is gone, and the user input can't be recorded.
So I am losing access to the ability to respond to a notification in my app. Is there anything that can be done to solve this problem? Thanks!
Only way to do that is to keep track on notification outside notification system. Unfortunately notification system is not allowing you to read any data about notifications you set.
Whenever you set a notification add it to a list of notifications with a date when it will be launched. When user enters your application go through your local list and see which notification expired (date < NOW).