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

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.

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.

Local notification behaviour

When my application is not active (in background) I recive local notification. After click on this notification application became active. Is it possible to activate application after I recive local notification automaticaly, without clicking on it
No, this is not possible.
From Local and Push Notification Programming Guide
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.
An action performed by the user is required.
No,
you cannot start any application automatically from background without user getting some actions.
So, for local notifications, application cannot be resumed from background even if local notification is fired. User has to click on notification to open application.
Hope this info helps you..

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.

iPhone local notification in different application states

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.

iPhone Notifications is possible to

I read more post regarding iPhone notification, and I have a simple question....
Where a device receive a notification (so I can display a message contains the message notificatio ti advise the user).
I understand that message is managed by the application.
The question is:
...when my application receive the notification is it possible to start it?
Or in other world the application became run when receive the notification or it simple became active only to manage the message and at the end of notification management the app return to sleep?
The main application windows is opened on the device ?
Many thanks in advance
Lukenukem
Ciao
With push notifications you can prompt the user to take action, which if they agree (by tapping the "open application" button), will open the application automatically.
The caveat is that you can't do this without the users consent. They have to tap the open application button for your app to open. There's no way to open the app automatically without the user's action, nor is there any way to open, perform the required actions and quit the app automatically.
The apps dont "sleep" they are either running or not (till 4.0 OS that is), im assuming you are asking about push notification, what happens when a user receives a notification is that they can choose to close it, or go ahead and "view" the notification which can cause the app to open automatically...thats as far is it goes in the current system i blive...