How to bring iphone app from background to foregro

2019-09-06 08:46发布

问题:

This question already has an answer here:

  • Relaunch iOS app without user interface when application in background? 4 answers

Please suggest me objective c code for bringing the app from background to foreground without any user interaction when push notification comes.

回答1:

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.



回答2:

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.



回答3:

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.