📦 SwiftyLaunch Modules
🔔 NotifKit
Sending Push Notifications

Sending Push Notifications

NotifKit (SwiftyLaunch Module) - Sending Push Notifications

After completing the initial project setup, you can start sending push notifications to your users, without having to do any extra work.

Using the OneSignal Dashboard

Sometimes you might want to send a push notification to your users without having to set up the whole process, or just to test if everything is even working correctly. For this, go your app in the OneSignal Dashboard (opens in a new tab). In the sidebar, select Messages > Push. Here you can create a new push notification and send it to your users.

In this example, we will send an an immidiate push notification to all of our current app users that have agreed to receive push notifications.

OneSignal Dashboard - Sending a Push Notification, Step 1 OneSignal Dashboard - Sending a Push Notification, Step 2 OneSignal Dashboard - Sending a Push Notification, Step 3

When deploying an application, you would want to send individual notifications to users, or segments of users (opens in a new tab), using the provided BackendKit integration or by calling the Rest API manually. Both of these methods are described below.

Using BackendKit

To send a Push Notification using BackendKit (based on Firebase Cloud Functions), refer to our NotifKit integration section in the BackendKit Documentation.

Using OneSignal's Rest API

If you're rocking your own backend and want to send push notifications from there, you can use OneSignal's REST API to send push notifications to your users.

Here's an example that you can copy and paste into your terminal to send a push notification to a user of your app:

curl --include \
     --request POST \
     --header "Content-Type: application/json; charset=utf-8" \
     --header "Authorization: Basic <YOUR_REST_API_KEY>" \
     --data-binary "{
         \"app_id\": \"<YOUR_APP_ID>\",
         \"include_aliases\": { \"external_id\": [\"<FIREBASE_USER_ID>\"] },
         \"target_channel\": \"push\",
         \"contents\": {\"en\": \"Message Body\"},
         \"headings\": {\"en\": \"Message Title\"}
     }" \
     https://api.onesignal.com/notifications

Dont forget to:

  • Replace <YOUR_REST_API_KEY> with your OneSignal REST API Key
  • Replace <YOUR_APP_ID> with your OneSignal App ID
  • Replace <FIREBASE_USER_ID> with the Firebase User ID of the user you want to send the push notification to

Check out the whole OneSignal REST API documentation (opens in a new tab) to see how to do other things, such as starting live activities, creating user segments, templates and more