Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Handling pushed notifications with APNS

Considering that I receive a pushed notification on my iPhone.

What happens:

  1. If the application is started: is there a way to get the payload? Do I see the notification on my screen?
  2. If the application is not started, is there a way to get the payload?

Thx for your answers

like image 805
Eric V Avatar asked Jul 02 '10 16:07

Eric V


People also ask

Does iOS support push notification?

An iOS push notification is a message that pops up on an Apple device such as an iPhone. Before receiving push notifications from an app, iOS device users must explicitly give permission. Once a user opts-in, mobile app publishers can send push notifications to the users' mobile devices.

How do I check my APN push notifications online?

PushTry is an online testing tool which helps you to test APNS and GCM online from your browser. This is one of the simple and powerful online push notification testing tool available on the internet. PushTry supports major functionalities to test APNS and GCM. If you want us to add any feature then please contact us.

How do I set up push notifications on iOS?

Setting up Push Notifications in iOS. Go back to the iOS project you created earlier and select the main target. Under the Signing & Capabilities tab, click on the + Capability button, then select Push Notifications. This will enable your app to receive push notifications from OneSignal.

How do I test iOS push notifications?

To send a test push, go to Mobile Apps > Integrations > Test Push. Use the Apple Sandbox Certificates for Xcode and the Apple Production Certificates when testing from TestFlight.


1 Answers

First of all push notifications are not “strong”, if you simply let a notification sit for long enough (e.g. phone turned off for many days) it will get discarded. You need to do some custom back-end processing to persist the content sent in notifications.

In the UIApplicationDelegate protocol there’s application:didFinishLaunchingWithOptions:. If your app is launched by the user tapping the right button in an alert of a push notification, the launchOptions dictionary bound to the method call will contain information regarding that notification; if your app is already running then application:didReceiveRemoteNotification: (also in the delegate protocol) will get called instead.

So,

  • If the application is started, and you implement application:didReceiveRemoteNotification: then yes you get the payload. Otherwise, nothing happens.

  • If the application is not started at the time the notification is sent, then the user taps on the alert of the notification and launches your app, your app gets the payload if it implements application:didFinishLaunchingWithOptions:. Otherwise, you get nothing.

like image 98
Evadne Wu Avatar answered Oct 25 '22 20:10

Evadne Wu