Adbrix Growth Action Integration [iOS - Swift]
FollowRequirement
Before Growth Action integration, you have to finish adbrix iOS SDK integration [Swift].
[[인용:위험:보통]] Growth Action requires iOS 10 and higher.
[[인용:안내:보통]] For adbrix Growth Action
_ You can send targeting&scenario push using Growth Action.
_ Growth Action is Premium Add-on, you have to pay an extra charge fee for it. [Contact us for Growth Action]
Growth Action Setting(Mandatory)
Register Certificates
You have to register certificates for adbrix iOS Growth Action.
Go to adbrix console > Growth Action > Settings > iOS Push Setting.
Set your certificates like the following screenshot.
[[인용:경고:보통]] Caution!!
_ Register p12 certificate without a password.
_ You have to set the p12 certificate as Production type.
_ adbrix iOS Growth Action runs only in a Production environment.
Add Capability
Go to your project's Signing & Capabilities.
Click the '+' button and add 'Background Modes'.
Check 'Remote notifications'.
Add Framework
Go to your project's General.
Add 'NotificationCenter.framework' and 'UserNotifications.framework'.
Add Notification Service Extension
You have to add a Notification Service Extension.
a. Click the '+' button at the bottom of Xcode.
b. Choose 'Notification Service Extension' and click the next button.
c. Type Product Name and click the Finish button.
d. Go to the Extension's General.
Find the 'AdBrixRM.framework'. It is located under your project's Pods > AdBrixRemastered folder.
Add the file to Frameworks and Libraries.
e. Now you can find NotificationService.swift file on your Xcode navigator.
Open the NotificationService.swift file and edit your code like the following.
import UserNotifications import AdBrixRM class NotificationService : AdBrixPushService {}
Edit AppDelegate.swift
a. Add the following code within AppDelegate.swift to get a device token.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){ let adBrix = AdBrixRM.getInstance adBrix.setRegistrationId(deviceToken: deviceToken) }
b. Depending on a user's agreement, add push on/off within didFinishLaunchingWithOptions.
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { ... let unCenter = UNUserNotificationCenter.current() unCenter.delegate = self let options : UNAuthorizationOptions = [.alert,.sound,.badge] unCenter.requestAuthorization(options: options, completionHandler: {(granted,error) in if granted{ DispatchQueue.main.async { // If Push permission is granted enable AdBrix Push AdBrixRM.getInstance.setPushEnable(toPushEnable: true) application.registerForRemoteNotifications() UIApplication.shared.registerForRemoteNotifications() } } else{ // If Push permission is not granted disable AdBrix Push AdBrixRM.getInstance.setPushEnable(toPushEnable: false) } }) ... }
[[인용:경고:보통]] Check Adbrix Push Setting
Before using growth action, getting agreement from users is mandatory.
You have to call Push-On API from the users who have already agreed with the push.
c. Add push notification click tracking function.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { AdBrixRM.getInstance.userNotificationCenter(center: center, response: response) completionHandler() }
[[인용:안내:보통]] Congratulations!!
Now you are ready to use adbrix Growth Action.
From now on, you can receive a server push. If you want to set additional push options, continue to follow this guide.
Growth Action Setting (Additional)
Set push notification delegate
Set local and server push delegate in your app.
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, AdBrixRmPushLocalDelegate, AdBrixRmPushRemoteDelegate { ... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { ... adBrix.setAdBrixRmPushLocalDelegate(delegate: self) // Local Push Delegate adBrix.setAdBrixRmPushRemoteDelegate(delegate: self) // Reomte Push Delegate ... } // Local Push Delegate func pushLocalCallback(data: Dictionary<String, Any>?, state: UIApplication.State) { print("Local Push Received") } // Reomte Push Delegate func pushRemoteCallback(data: Dictionary<String, Any>?, state: UIApplication.State) { print("Remote Push Received") } ... }
[[인용:위험:보통]] Each delegate works only while the app is running in the foreground after push is clicked.
[[인용:위험:보통]] Caution!!
You have to deal with NullPointerException when you register remote push Delegate. We do not send any data when you choose the 'AppOpen' option.
Local Push Setting
Call local push
This is an example code of local push.
@IBAction func localPushEvent(_ sender: Any) { let calendar = Calendar.current let alarmTime = calendar.date(byAdding: .second, value: 5, to: Date()) let notisound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "mySound.aiff")) AdBrixRM.getInstance.registerLocalPushNotification(id: "12345", date: alarmTime!, title: "this is Title", subtitle: "this is subtitle", body: "This is text", sound: notisound, categoryId: nil, threadId: nil, badgeNumber: 3, image:URL(string: "https://myURL.com/myImage.jpg"), attrDic: ["customKey" : "customValue"], completionHandler: {(isRegSucc,error,pushid)in print("registerLocalPushnotification is RegSucc:: \(isRegSucc) : \(pushid)") }) }
The following screenshot is how the example code looks on an iOS device.
property value
- id: unique ID for push registration
- date: the time when push is called
- title: upper title
- subtitle: lower title
- body: main message
- sound: push sound(in case of nil, basic sound)
- categoryId: category ID
- threadId: thread ID
- badgeNumber: badge number on an app icon
- image: local or server image for push(if you use server image, you have to use 'https://')
- attrDic: extra dictionary data
- completionHandler: push register callback listener
- isRegSucc: whether succeed or not push registration
- error: error message about push failure(success data is nil)
- pushId: registered push ID
Local Push Control
This code is how to control local pushes registered on your app.
// A List of Current Local Pushes AdBrixRM.getInstance.getRegisteredLocalPushNotification(completeHandler: {(idArr) in print(“myLocalPushList : \(idArr)“) }) // Cancel the specific Local Push with ID let arr : Array = ["pushid1"] AdBrixRM.getInstance.cancelLocalPushNotification(ids: arr) // Cancel all Local Pushes AdBrixRM.getInstance.cancelLocalPushNotificationAll()
- getRegisteredLocalPushNotification: You can call a list of registered local pushes in your app
- cancelLocalPushNotification:n You can cancel specific local push with an ID
- cancelLocalPushNotificationAll: You can cancel all the local pushes registered on the app