1
1
# Testing Push Notifications on iOS Simulator
2
2
3
3
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
5
5
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.
7
7
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
9
9
Simulator.
10
10
11
- <div id =" receive-notification " />
12
11
13
- ## Receive a notification on the iOS Simulator
12
+ ### Contents
14
13
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 )
16
17
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 ) .
21
35
22
36
23
37
### 1. Determine the device ID of the iOS Simulator
@@ -46,8 +60,8 @@ $ xcrun simctl list devices booted
46
60
### 2. Trigger a notification by pushing the payload to the iOS Simulator
47
61
48
62
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.
51
65
52
66
``` shell-session
53
67
$ xcrun simctl push [device-id] com.zulip.flutter [payload json path]
@@ -64,19 +78,21 @@ Notification sent to 'com.zulip.flutter'
64
78
</details >
65
79
66
80
67
- <div id =" pre- canned-payloads" />
81
+ <div id =" canned-payloads " />
68
82
69
- ## Pre-canned APNs payloads
83
+ ## Canned APNs payloads
70
84
71
85
The following pre-canned APNs payloads can be used in case you don't
72
86
have one.
73
87
74
- The following pre- canned payloads were generated from
88
+ These canned payloads were generated from
75
89
Zulip Server 11.0-dev+git 8fd04b0f0, API Feature Level 377,
76
90
in April 2025.
91
+ The
` user_id ` is that of
` [email protected] ` in the Zulip dev environment.
77
92
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 )
80
96
in order to enable your device to connect to the dev server, you'll
81
97
need to adjust the ` realm_url ` fields. You can do this by a
82
98
find-and-replace for ` localhost ` ; for example,
@@ -190,16 +206,16 @@ canned payloads to files `tmp/*.json`.
190
206
</details >
191
207
192
208
193
- <div id =" retrieve-apns -payload" />
209
+ <div id =" produce -payload" />
194
210
195
- ## Retrieve an APNs payload from dev server
211
+ ## Produce sample APNs payloads
196
212
197
213
### 1. Set up dev server
198
214
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 .
203
219
204
220
If you want to run the dev server on a different machine than the Mac
205
221
host, you'll need to follow extra steps
@@ -210,34 +226,34 @@ connect to the dev server.
210
226
211
227
### 2. Set up the dev user to receive mobile notifications.
212
228
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.
215
231
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 )
217
233
to enable Mobile Notifications for "Channels".
218
234
219
235
220
236
### 3. Log in as the dev user on zulip-flutter.
221
237
222
238
<!-- TODO(#405) Guide to use the new devlogin page instead -->
223
239
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
225
241
that was generated by the development server. You can print the
226
242
password by running this command inside your ` vagrant ssh ` shell:
227
243
```
228
244
$ ./manage.py print_initial_password [email protected]
229
245
```
230
246
231
247
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
233
249
234
250
235
251
236
252
### 4. Edit the server code to log the notification payload.
237
253
238
254
We need to retrieve the APNs payload the server generates and sends
239
255
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 ` :
241
257
242
258
``` diff
243
259
apns_payload = get_message_payload_apns(
@@ -270,12 +286,15 @@ by searching for "APNS payload".
270
286
271
287
### 6. Transform and save the payload to a file
272
288
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:
276
295
277
296
``` shell-session
278
297
$ echo '{"alert":{"title": ...' \
279
- | jq '{aps: {alert: .alert , sound: .sound, badge: . badge}, zulip: .custom.zulip}' \
298
+ | jq '{aps: {alert, sound, badge}, zulip: .custom.zulip}' \
280
299
> payload.json
281
300
```
0 commit comments