Getting started
Installation
Required:
- Valid iOS Push Token
- Physical iOS device (Push services doesn't work in Simulator)
- Redlink account with
AppId,Token,SecretandEvents Token - Application with deployment target equal or above iOS 10.0
Steps:
- Add notification service extension
- Import Redlink framework into your project
- Configure Xcode project
- Add required code
1. Add notification service extension
- In Xcode select
File->New->Target - Select
Notification Service Extensionand pressNext - Fill in
Product Namewithproject_nameNotificationServiceExtension(changeproject_nameto name of your project) - Select
SwiftunderLanguagesection (Even if your project is written inObj-C) - Skip Activate scheme alert using
Cancel - Remove a class body generated by Xcode, import Redlink framework and use
RedlinkNotificationServiceExtensionas 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'
end
target 'project_name' do
shared_pods
end
target 'project_nameNotificationServiceExtension' do
shared_pods
endRun pod install in command line.
3. Configure Xcode project
- Select your project in
Navigator - Select
Capabilitiesin top toolbar - Enable
Push Notifications
4. Add RedlinkConfig.plist
- Select in Xcode
File->New->File - Under Resource section select
Property List - Fill
SaveAswith nameRedlinkConfig.plistand select Targets (should be both,project_nameandproject_nameNotificationServiceExtension) - Right click on added
RedlinkConfig.plistand selectOpen 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">
<dict>
<key>AppId</key>
<string>your_application_id</string>
<key>Token</key>
<string>your_application_token</string>
<key>Secret</key>
<string>your_application_secret</string>
<key>EventsToken</key>
<string>your_application_events_token</string>
</dict>
</plist>- Replace
your_application_id,your_application_token,your_application_secretandyour_application_events_tokenwith variables obtained from Redlink dashboard.
5. Add required code
- Open your
AppDelegateclass - Import Redlink framework using
import Redlink - Add the following code to
didFinishLaunchingWithOptionsmethod:
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:
Redlink.userYou can change each of the following data fields:
- email
String - phone
String - firstName
String - lastName
String - customParameters
[String: Any]- whereAnyisStringorIntorBoolorDate. Any other type of value will be ignored and removed automatically
Validation:
emailrequires valid email formatemail,companyName,firstName,lastNamecan 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"
]
userData.saveUser()
}There is also posibility to remove all stored user data. To do that call:
Redlink.user.removeUser()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:
Redlink.user.saveUser()Analytics
In order to track custom user events use RedlinkAnalytics class. It can be accessed in:
Redlink.analyticsEach 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.
Validation:
EventNamecan be up to 64 length characters- Param
keycan 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
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] = [:]) -> BoolRemember 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:
RedlinkPushOptions.default()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 = selfRequired 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 = selfThe 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.