AppId
, Token
, Secret
and Events Token
File
-> New
-> Target
Notification Service Extension
and press Next
Product Name
with project_nameNotificationServiceExtension
(change project_name
to name of your project)Swift
under Language
section (Even if your project is written in Obj-C
)Cancel
RedlinkNotificationServiceExtension
as a superClass. Your extension should now look like this:import Redlink
class project_nameNotificationServiceExtension: RedlinkNotificationServiceExtension {
}
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
end
Run pod install
in command line.
Navigator
Capabilities
in top toolbarPush Notifications
File
-> New
-> File
Property List
SaveAs
with name RedlinkConfig.plist
and select Targets (should be both, project_name
and project_nameNotificationServiceExtension
)RedlinkConfig.plist
and select Open As
-> Source Code
<?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>
your_application_id
, your_application_token
, your_application_secret
and your_application_events_token
with variables obtained from Redlink dashboard.AppDelegate
classimport Redlink
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
}
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.
In order to update information about user use RedlinkUserData class. It can be accessed in:
Redlink.user
You can change each of the following data fields:
String
String
String
String
[String: Any]
- where Any
is String
or Int
or Bool
or Date
. Any other type of value will be ignored and removed automaticallyValidation:
email
requires valid email formatemail
, companyName
, firstName
, lastName
can be up to 64 length charactersAfter 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()
In order to track custom user events use RedlinkAnalytics
class. It can be accessed in:
Redlink.analytics
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.
Validation:
EventName
can be up to 64 length characterskey
can be up to 64 length charactersBesides 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
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.
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)
}
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)
}
}
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.
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)
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.
link |
Stars: 2 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics