Swiftpack.co - vercomsa/redlink-push-ios-sdk as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by vercomsa.
vercomsa/redlink-push-ios-sdk 1.1.14
⭐️ 2
🕓 2 weeks ago
.package(url: "https://github.com/vercomsa/redlink-push-ios-sdk.git", from: "1.1.14")

Getting started



  • Valid iOS Push Token
  • Physical iOS device (Push services doesn't work in Simulator)
  • Redlink account with AppId, Token, Secret and Events Token
  • Application with deployment target equal or above iOS 10.0


  1. Add notification service extension
  2. Import Redlink framework into your project
  3. Configure Xcode project
  4. Add required code

1. Add notification service extension

  • In Xcode select File -> New -> Target
  • Select Notification Service Extension and press Next
  • Fill in Product Name with project_nameNotificationServiceExtension (change project_name to name of your project)
  • Select Swift under Language section (Even if your project is written in Obj-C)
  • Skip Activate scheme alert using Cancel
  • Remove a class body generated by Xcode, import Redlink framework and use RedlinkNotificationServiceExtension as a superClass. Your extension should now look like this:
import Redlink

class project_nameNotificationServiceExtension: RedlinkNotificationServiceExtension {


2. Import Redlink into your project

Redlink can be imported by using CocoaPods. If you are not familiar with CocoaPods please check official guide.

Use the following code in your Podfile. Remember that Redlink Pod must be also added to NotificationServiceExtension target.

def shared_pods
  pod 'Redlink', ~> '1.0'

target 'project_name' do

target 'project_nameNotificationServiceExtension' do

Run pod install in command line.

3. Configure Xcode project

  • Select your project in Navigator
  • Select Capabilities in top toolbar
  • Enable Push Notifications

4. Add RedlinkConfig.plist

  • Select in Xcode File -> New -> File
  • Under Resource section select Property List
  • Fill SaveAs with name RedlinkConfig.plist and select Targets (should be both, project_name and project_nameNotificationServiceExtension)
  • Right click on added RedlinkConfig.plist and select Open As -> Source Code
  • Add following code instead of original one
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  • Replace your_application_id, your_application_token, your_application_secret and your_application_events_token with variables obtained from Redlink dashboard.

5. Add required code

  • Open your AppDelegate class
  • Import Redlink framework using import Redlink
  • Add the following code to didFinishLaunchingWithOptions method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  Redlink.configure(using: RedlinkConfiguration.defaultConfiguration())
  Redlink.push.registerForPushNotifications(with: RedlinkPushOptions.default())
  return true

6. Note

Please note that automatic configuration might cause unexpected behavior when Redlink is being used along with Firebase and other frameworks which swizzle the same methods. If so please consider using custom configuration.

User Identification

In order to update information about user use RedlinkUserData class. It can be accessed in:


You can change each of the following data fields:

  • email String
  • phone String
  • firstName String
  • lastName String
  • customParameters [String: Any] - where Any is String or Int or Bool or Date. Any other type of value will be ignored and removed automatically


  • email requires valid email format
  • email, companyName, firstName, lastName can be up to 64 length characters

After changing user data you have to manually save it. To do that call:

func saveUser()

Full example of updating user data:

func updateUser() {
    let userData = Redlink.user
    userData.email = "[email protected]"
    userData.firstName = "Redlink"
    userData.customParameters = [
        "myKey": "myValue"

There is also posibility to remove all stored user data. To do that call:


If you want also to unsubscribe user from Redlink Push Notification Services you can also use additional parameter while removing user like so:

Redlink.user.removeUser(deletePushToken: true)

You can use that when the user did sign out and you don't want to send notifications for that user. To make the current user's device to receive push notifications back again you need to call:



In order to track custom user events use RedlinkAnalytics class. It can be accessed in:


Each event is identified by EventName. In order to track an event use:

Redlink.analytics.trackEvent(withName: "event_name")

You can also provide additional parameters to an event:

Redlink.analytics.trackEvent(withName: "event_name", parameters: [
    "myKey": "myValue"

Parameters are of type [String: Any] - where Any is String or Int or Bool or Date. Any other type of value will be ignored and removed automatically.


  • EventName can be up to 64 length characters
  • Param key can be up to 64 length characters

Besides paramaters you can inject userData as Valid JSON String:

Redlink.analytics.trackEvent(withName: "event_name", userData: "{\"foo\":\"bar\"}")


Deeplinking works using the official Apple SDK. In order to handle received URL use:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

Remember to register your custom URL scheme. You can find more detailed information in official documentation

Advanced Configuration

RedlinkPush Custom Configuration

Besides standard configuration, where all the necessary initialization is performed automatically by Redlink framework, it is also possible to manually configure the framework.

When initializing RedlinkPush in AppDelegate you can use RedlinkPushOptions with default options:


Or you can create RedlinkPushOptions instance with custom configuration:

RedlinkPushOptions(authorizationOptions: RedlinkPushAuthorizationOptions, useAutomaticConfiguration: Bool)

By default useAutomaticConfiguration is set to true which means that all important iOS events related to push notifications such as registration of APNS token, receiving a push notification etc. are automatically handled by Redlink framework (using methods swizzling).

If useAutomaticConfiguration is set to false then you are required to manually inject all the necessary information to Redlink framework. In such case you have more control over the framework but you need to add some additional code in classes and methods mentioned below.

1. AppDelegate

You need to invoke these methods in Redlink.push:

func didRegisterForRemoteNotifications(with deviceToken: Data)
func didFailToRegisterForRemoteNotifications(with error: Error)

Required changes example:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Redlink.push.didRegisterForRemoteNotifications(with: deviceToken)

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    Redlink.push.didFailToRegisterForRemoteNotifications(with: error)

2. UNUserNotificationCenter

You need to invoke these methods in Redlink.push:

func willPresentNotification(_ notification: UNNotification)
func didReceiveNotificationResponse(response: UNNotificationResponse)

willPresentNotification gives you opportunity to change UNNotificationPresentationOptions for current notification. By default Redlink uses [.alert] for all notifications.

In order to make it possible please conform to the UNUserNotificationCenterDelegate protocol inside your AppDelegate implementation like so:

UNUserNotificationCenter.current().delegate = self

Required changes example:

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler(Redlink.push.willPresentNotification(notification, presentationOptions: []))
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        Redlink.push.didReceiveNotificationResponse(response: response)

Additional Information

In order to receive additional information about a notification, it is possible to set a custom delegate (RedlinkPushDelegate) in RedlinkPush:

Redlink.push.delegate = self

The delegate has 4 optional methods and each of them has userInfo parameter with all data available in notification payload.

Push Notification Actions

Actions can be invoked by interacting on notification (tap action) or notification action buttons. Action will always open application firstly, then perform expected action

Each action has one of the four action types:

BROWSER - opens the Safari browser

WEBVIEW - opens the RedlinkWebViewController, by default it uses the current visible controller from UIApplication.shared.keyWindow to perform presentation

DEEPLINK - performs UIApplication.shared.open with given URL.

NONE - do nothing (notification disappears)

Demo app

We provide demo app to simply show you what Redlink is capable of. This will also show you how simple it is to configure the framework within your project. Please check Demo directory to get your hands on.


Stars: 2
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics