How to Test Apple Push Notification Service Without an Iphone

How can I test Apple Push Notification Service without an iPhone?

Testing push notifications using the Xcode 11.4 iOS Simulator

As of Xcode 11.4, it is now possible to simulate push notifications by dragging and dropping an .apns file onto the iOS simulator. The Xcode 11.4 release notes have the following to say about the new feature:

Simulator supports simulating remote push notifications, including
background content fetch notifications. In Simulator, drag and drop an
APNs file onto the target simulator
. The file must be a JSON file with
a valid Apple Push Notification Service payload, including the “aps”
key
. It must also contain a top-level “Simulator Target Bundle” with a
string value matching the target application‘s bundle identifier.

simctl also supports sending simulated push notifications. If the file
contains “Simulator Target Bundle” the bundle identifier is not
required, otherwise you must provide it as an argument (8164566):

xcrun simctl push com.example.my-app ExamplePush.apns

Example

Here is an example for such an .apns file, targeted towards the system settings app:

{
"Simulator Target Bundle": "com.apple.Preferences",
"aps": {
"alert": "This is a simulated notification!",
"badge": 3,
"sound": "default"
}
}

Dragging and dropping this onto the target simulator will present the notification and set the badge:

Notification on the iOS simulator

Now, to use this for debugging purposes, you only have to change the Simulator Target Bundle to your own app's identifier and adjust the payload to your debugging needs!

How to test Apple Push Notifications Feedback Service?

Okay, so from what I have discovered, seems that Instant Feedback service from Apple is working just fine and is able to detect uninstall pretty fast. There was a small trick in how to test these things properly with sandbox service.

If you make an app which you are testing locally on your device and your app is the only one installed on your phone from that provisioning profile (vendor), stuff which I faced as an issue in my question will be encountered. For some reason, even if you uninstall the app (which was the only one on the phone installed from your provisioning profile), Apple is always responding with 200.

What needs to be done is following: After you install your app which you are testing, create a new dummy app with another bundle ID, but which also coming from your provisioning profile, enable push notifications in it as well and install it on your device. So now, you have two apps that you made - one which you are developing and testing the Instant Feedback service with and another one which kinda "zombie" app which just sits in there and does nothing.

After this, uninstall your test app, try to send silent push notification and Apple will respond with status code 410 as expected.

Dummy way, but for some reason that's how it should be while testing. Behaviour in production should be as expected and w/o any need to have a dummy (or any other) app from same vendor installed on iOS device.

Is this possible to test push notification without developer ID?

In order to use Apple push notifications you'll need to generate a certificate for your app in the member's center which can only be accessed if you have a current membership to the Apple Developer Program.

Test for Apple Push Notification

In many situations, while writing tests, it is either impossible or simply too dangerous to verify that an action has really taken place (i.e. a push notification has been delivered). Imagine writing a unit test for the rm command where you would like to ensure that doing rm -rf / succeeds. Obviously, you cannot let this action take place and verify that your root partition is indeed empty!

What you can do, however (and should do, really), is verify that whatever commands, routines or other actions necessary to accomplish the task are being invoked correctly, without actually allowing them to take place.

In your particular situation, you do not need to verify that your push notification has been delivered because your application is not responsible for the notification's delivery. However, you can test that the push notification is being correctly delivered to the push server.

So, instead of testing for successful delivery, you test

  1. Whether the outgoing request is properly formatted (i.e. JSON is valid)
  2. Whether it contains the data you expect it to contain (i.e. a field in JSON is present and contains expected data)
  3. Whether the authentication token required by the server is included
  4. Whether the target server is correct (i.e. you are indeed sending the data to xxx.apple.com and not to localhost)

Ideally, these test requests will not even reach the target server - doing so would mean you are relying on two factors that are not always perfectly stable:

  • network connectivity
  • target server availability and proper functionality

In the past, I dealt with this so that I first manually issued a correct request, captured the response and then mocked the whole communication in the unit test (using i.e. nock. That way, I am completely in control of the whole communication.

How to setup remote notifications without certificate? (RN)

No, a paid Apple Developer Program membership is required to use push notifications.

How to test push notifications in iOS?

You need distribute the Distribution version of your app using ad hoc.

When your application ready for submission, you create an ad hoc provisioning profile specifying an App ID that matches one or more of your apps, a set of test devices, and a single distribution certificate.

Here is an image to illustrate how the provision profile works:

Sample Image



Related Topics



Leave a reply



Submit