Skip to content

Commit 5df6033

Browse files
committed
docs: Clarify and expand a few spots in the iOS simulator notif doc
Also make use of a handy shorthand within `jq`.
1 parent 865341e commit 5df6033

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

docs/howto/push-notifications-ios-simulator.md

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
# Testing Push Notifications on iOS Simulator
22

33
For documentation on testing push notifications on Android or a real
4-
iOS Device, see https://github.com/zulip/zulip-mobile/blob/main/docs/howto/push-notifications.md
4+
iOS device, see https://github.com/zulip/zulip-mobile/blob/main/docs/howto/push-notifications.md
55

6-
This doc describes how to test client side changes on iOS Simulator.
6+
This doc describes how to test client-side changes on iOS Simulator.
77
It will demonstrate how to use APNs payloads the server sends to
8-
Apple's Push Notification service to show notifications on iOS
8+
the Apple Push Notification service to show notifications on iOS
99
Simulator.
1010

11-
<div id="receive-notification" />
1211

13-
## Receive a notification on the iOS Simulator
12+
### Contents
1413

15-
Follow the following steps if you already have a valid APNs payload.
14+
* [Trigger a notification on the iOS Simulator](#trigger-notification)
15+
* [Canned APNs payloads](#canned-payloads)
16+
* [Produce sample APNs payloads](#produce-payload)
1617

17-
Otherwise, you can either use one of the pre-canned payloads
18-
provided [here](#pre-canned-payloads), or you can retrieve the APNs
19-
payload generated by the latest dev server by following the steps
20-
[here](#retrieve-apns-payload).
18+
19+
<div id="trigger-notification" />
20+
21+
## Trigger a notification on the iOS Simulator
22+
23+
The iOS Simulator permits delivering a notification payload
24+
artificially, as if APNs had delivered it to the device,
25+
but without actually involving APNs or any other server.
26+
27+
As input for this operation, you'll need an APNs payload,
28+
i.e. a JSON blob representing what APNs might deliver to the app
29+
for a notification.
30+
31+
To get an APNs payload, you can generate one from a Zulip dev server
32+
by following the [instructions in a section below](#produce-payload),
33+
or you can use one of the payloads included
34+
in this document [below](#canned-payloads).
2135

2236

2337
### 1. Determine the device ID of the iOS Simulator
@@ -46,8 +60,8 @@ $ xcrun simctl list devices booted
4660
### 2. Trigger a notification by pushing the payload to the iOS Simulator
4761

4862
By running the following command with a valid APNs payload, you should
49-
receive a notification on the iOS Simulator for the zulip-flutter app,
50-
and tapping on it should route to the respective conversation.
63+
receive a notification on the iOS Simulator for the zulip-flutter app.
64+
Tapping on the notification should route to the respective conversation.
5165

5266
```shell-session
5367
$ xcrun simctl push [device-id] com.zulip.flutter [payload json path]
@@ -64,19 +78,21 @@ Notification sent to 'com.zulip.flutter'
6478
</details>
6579

6680

67-
<div id="pre-canned-payloads" />
81+
<div id="canned-payloads" />
6882

69-
## Pre-canned APNs payloads
83+
## Canned APNs payloads
7084

7185
The following pre-canned APNs payloads can be used in case you don't
7286
have one.
7387

74-
The following pre-canned payloads were generated from
88+
These canned payloads were generated from
7589
Zulip Server 11.0-dev+git 8fd04b0f0, API Feature Level 377,
7690
in April 2025.
91+
The `user_id` is that of `[email protected]` in the Zulip dev environment.
7792

78-
Also, they assume that EXTERNAL_HOST has its default value for the dev
79-
server. If you've [set EXTERNAL_HOST to use an IP address](https://github.com/zulip/zulip-mobile/blob/main/docs/howto/dev-server.md#4-set-external_host)
93+
These canned payloads assume that EXTERNAL_HOST has its default value
94+
for the dev server. If you've
95+
[set EXTERNAL_HOST to use an IP address](https://github.com/zulip/zulip-mobile/blob/main/docs/howto/dev-server.md#4-set-external_host)
8096
in order to enable your device to connect to the dev server, you'll
8197
need to adjust the `realm_url` fields. You can do this by a
8298
find-and-replace for `localhost`; for example,
@@ -190,16 +206,16 @@ canned payloads to files `tmp/*.json`.
190206
</details>
191207

192208

193-
<div id="retrieve-apns-payload" />
209+
<div id="produce-payload" />
194210

195-
## Retrieve an APNs payload from dev server
211+
## Produce sample APNs payloads
196212

197213
### 1. Set up dev server
198214

199-
Follow
200-
[this setup tutorial](https://zulip.readthedocs.io/en/latest/development/setup-recommended.html)
201-
to setup and run the dev server on same the Mac machine that hosts
202-
the iOS Simulator.
215+
To set up and run the dev server on the same Mac machine that hosts
216+
the iOS Simulator, follow Zulip's
217+
[standard instructions](https://zulip.readthedocs.io/en/latest/development/setup-recommended.html)
218+
for setting up a dev server.
203219

204220
If you want to run the dev server on a different machine than the Mac
205221
host, you'll need to follow extra steps
@@ -210,34 +226,34 @@ connect to the dev server.
210226

211227
### 2. Set up the dev user to receive mobile notifications.
212228

213-
We'll use the devlogin user `[email protected]` to test notifications,
214-
log in to that user by going to `/devlogin` on that server on Web.
229+
We'll use the devlogin user `[email protected]` to test notifications.
230+
Log in to that user by going to `/devlogin` on that server on Web.
215231

216-
And then follow the steps [here](https://zulip.com/help/mobile-notifications)
232+
Then follow the steps [here](https://zulip.com/help/mobile-notifications)
217233
to enable Mobile Notifications for "Channels".
218234

219235

220236
### 3. Log in as the dev user on zulip-flutter.
221237

222238
<!-- TODO(#405) Guide to use the new devlogin page instead -->
223239

224-
To login to this user in the Flutter app, you'll need the password
240+
To log in as this user in the Flutter app, you'll need the password
225241
that was generated by the development server. You can print the
226242
password by running this command inside your `vagrant ssh` shell:
227243
```
228244
$ ./manage.py print_initial_password [email protected]
229245
```
230246

231247
Then run the app on the iOS Simulator, accept the permission to
232-
receive push notifications, and then login to the dev user
248+
receive push notifications, and then log in as the dev user
233249
234250

235251

236252
### 4. Edit the server code to log the notification payload.
237253

238254
We need to retrieve the APNs payload the server generates and sends
239255
to the bouncer. To do that we can add a log statement after the
240-
server completes generating the APNs in `zerver/lib/push_notifications.py`:
256+
server completes generating the payload in `zerver/lib/push_notifications.py`:
241257

242258
```diff
243259
apns_payload = get_message_payload_apns(
@@ -270,12 +286,15 @@ by searching for "APNS payload".
270286

271287
### 6. Transform and save the payload to a file
272288

273-
The logged payload JSON will have different structure than what an
274-
iOS device actually receives, to fix that and save the result to a
275-
file, run the payload through the following command:
289+
The payload JSON recorded in the steps above is in the form the
290+
Zulip server sends to the bouncer. The bouncer restructures this
291+
slightly to produce the actual payload which it sends to APNs,
292+
and which APNs delivers to the app on the device.
293+
To apply the same restructuring, run the payload through
294+
the following `jq` command:
276295

277296
```shell-session
278297
$ echo '{"alert":{"title": ...' \
279-
| jq '{aps: {alert: .alert, sound: .sound, badge: .badge}, zulip: .custom.zulip}' \
298+
| jq '{aps: {alert, sound, badge}, zulip: .custom.zulip}' \
280299
> payload.json
281300
```

0 commit comments

Comments
 (0)