Silent pushes
Wake your app in the background to refresh its data, with no alert.
A silent push wakes your app in the background without showing anything. Apple delivers them at low priority and may hold or drop them, so use them to refresh data, never for anything the user must see.
In the app
- Under Signing & Capabilities, add Background Modes and tick Remote notifications. Setting
INFOPLIST_KEY_UIBackgroundModesas a build setting has no effect. - Pushwren doesn’t handle silent pushes for you. Add the handler to your app delegate (a
PushwrenAppDelegatesubclass works):
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]
) async -> UIBackgroundFetchResult {
// Refresh your data here, then:
return .newData
}
From your server
Set "options": { "pushType": "background" }, with no alert, badge or sound:
curl https://api.pushwren.com/v1/notifications \
-H "Authorization: Bearer $PUSHWREN_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"target": { "userIds": ["u_123"] },
"data": { "refresh": "inbox" },
"options": { "pushType": "background" }
}'
Your data keys arrive in userInfo, beside aps. See Notifications for every option.