The easiest way to support push notifications in your app.
Feature | Description |
---|---|
Automatic Token Management
|
Skip manually managing push notification device tokens. |
Notification Tracking
|
Track if your users are receiving your notifications even if your app is not runnning or open. |
Permission Requests & Checking
|
Simple functions to request and check push notification permission settings. |
Requirement | Reason |
---|---|
Apple Developer Membership
|
Apple requires all iOS developers to have a membership so you can manage your push notification certificates. |
A phyical iOS device | Although you can setup the Courier SDK without a device, a physical device is the only way to fully ensure push notification tokens and notification delivery is working correctly. Simulators are not reliable. |
A Configured Provider
|
Courier needs to know who to route the push notifications to so your users can receive them. |
Authentication
|
Needs Authentication to sync push notification device tokens to the current user and Courier. |
Select which push notification provider you would like Courier to route push notifications to. Choose APNS - Apple Push Notification Service if you are not sure which provider to use.
Provider | Token Syncing |
---|---|
(APNS) - Apple Push Notification Service
|
Automatic
|
(FCM) - Firebase Cloud Messaging
|
Manual
|
Expo
|
Manual
|
OneSignal
|
Manual
|
Pusher Beams
|
Manual
|
Enable.push.notification.mov
- Select your Xcode project file
- Click your project Target
- Click "Signing & Capabilities"
- Click the small "+" to add a capability
- Press Enter
- In your
AppDelegate
, addimport Courier_iOS
- Change your
AppDelegate
to extend theCourierDelegate
- This automatically syncs APNS tokens to Courier
- This adds simple functions to handle push notification delivery and clicks
import Courier_iOS
@main
class AppDelegate: CourierDelegate {
...
override func pushNotificationDeliveredInForeground(message: [AnyHashable : Any]) -> UNNotificationPresentationOptions {
print("\n=== 💌 Push Notification Delivered In Foreground ===\n")
print(message)
print("\n=================================================\n")
// This is how you want to show your notification in the foreground
// You can pass "[]" to not show the notification to the user or
// handle this with your own custom styles
return [.sound, .list, .banner, .badge]
}
override func pushNotificationClicked(message: [AnyHashable : Any]) {
print("\n=== 👉 Push Notification Clicked ===\n")
print(message)
print("\n=================================\n")
showMessageAlert(title: "Message Clicked", message: "\(message)")
}
}
Useful if you do not want to use CourierDelegate
or you would like to sync tokens from another provider into Courier.
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
...
// Manually Sync APNS tokens
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Task {
// Raw APNS token
try await Courier.shared.setAPNSToken(deviceToken)
let apnsToken = await Courier.shared.getToken(for: .apn)
}
}
// Commonly used with Firebase Cloud Messaging and other providers
func yourTokenFetchingFunction(token: String) {
Task {
// Sync with provider
// Available providers: .apn, .firebaseFcm, .expo, .oneSignal, .pusherBeams
try await Courier.shared.setToken(for: .firebaseFcm, token: token)
let token = await Courier.shared.getToken(for: .firebaseFcm)
// Sync with key
// Any string as key is supported. Make sure you are using the proper key for your needs.
try await Courier.shared.setToken(for: "firebase-fcm", token: token)
let token = await Courier.shared.getToken(for: "firebase-fcm")
}
}
}
To make sure Courier can track when a notification is delivered to the device, you need to add a Notification Service Extension. Here is how to add one.
courier-ios-notification-service-setup.mov
- Download and Unzip the Courier Notification Service Extension:
CourierNotificationServiceTemplate.zip
- Open the folder in terminal and run
sh make_template.sh
- This will create the Notification Service Extension on your mac to save you time
- Open your iOS app in Xcode and go to File > New > Target
- Select "Courier Service" and click "Next"
- Give the Notification Service Extension a name (i.e. "CourierService").
- Click Finish
- Click on your project file
- Under Targets, click on your new Target
- Under the General tab > Frameworks and Libraries, click the "+" icon
- Select the Courier package from the list under Courier Package > Courier
- Add the following snippet to the bottom of your Podfile
target 'CourierService' do
pod 'Courier_iOS'
end
- Run
pod install
- Register for push notifications
import Courier_iOS
Task {
// Make sure your user is signed into Courier
// This will take the tokens you are wanting to sync above, and save them to this user id
// Put this where you normally manage your user's state
await Courier.shared.signIn(
userId: "example_user_id",
accessToken: "...",
)
// Shows a popup where your user can allow or deny push notifications
// You should put this in a place that makes sense for your app
// You cannot ask the user for push notification permissions again
// if they deny, you will have to get them to open their device settings to change this
let status = try await Courier.requestNotificationPermission()
}
- Send a test message
Provider | Link |
---|---|
(APNS) - Apple Push Notification Service
|
Testing Docs
|
(FCM) - Firebase Cloud Messaging
|
Testing Docs
|
👋 TokenManagement APIs
can be found here