DFINERY Growth Action Integration [iOS]
FollowRequirement
Before Growth Action integration, you have to finish DFINERY iOS SDK.
[[인용:위험:보통]] Growth Action requires iOS 10 and higher.
[[인용:안내:보통]] For DFINERY 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
Register Certificates
You have to register certificates for DFINERY iOS Growth Action.
Go to DFINERY 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.
_ DFINERY 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 'AdBrixRmKit.framework'. It is located under your project's Pods > AdBrixRmKit 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.
//NotificationService.swift import UserNotifications import AdBrixRmKit class NotificationService : AdBrixPushService {}
//NotificationService.h #import <UserNotifications/UserNotifications.h> #import <AdBrixRmKit/AdBrixPushServiceObjC.h> @interface NotificationService : AdBrixPushServiceObjC @end //NotificationService.m #import "NotificationService.h" @interface NotificationService () @end
Edit AppDelegate
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) }
/- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { AdBrixRM * adBrix = [AdBrixRM sharedInstance]; [adBrix setRegistrationIdWithDeviceToken: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) } }) ... }
//AppDelegate.h #import <UIKit/UIKit.h> #import <UserNotifications/UNUserNotificationCenter.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> @end //AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if(granted){ [[UIApplication sharedApplication] registerForRemoteNotifications]; AdBrixRM * adBrix = [AdBrixRM sharedInstance]; [adBrix setPushEnableToPushEnable:true]; } else{ AdBrixRM * adBrix = [AdBrixRM sharedInstance]; [adBrix setPushEnableToPushEnable:false]; } }]; ... }
[[인용:경고:보통]] Check DFINERY 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() }
- (void) userNotificationCenter:(UNUserNotificationCenter )center didReceiveNotificationResponse:(UNNotificationResponse )response withCompletionHandler:(void (^)(void))completionHandler{ AdBrixRM * adBrix =[AdBrixRM sharedInstance]; [adBrix userNotificationCenterWithCenter:center response:response]; completionHandler(); }
[[인용:안내:보통]] Congratulations!!
Now you are ready to use DFINERY 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 { ... // Create AdBrixRM Instance let adBrix = AdBrixRM.getInstance // SDK init must call first adBrix.initAdBrix(appKey: "your_app_key", secretKey: "your_secret_key") 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") } ... }
//AppDelegate.h #import <UIKit/UIKit.h> #import <UserNotifications/UNUserNotificationCenter.h> #import <AdBrixRmKit/AdBrixRmKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate,AdBrixRmPushRemoteDelegate,AdBrixRmPushLocalDelegate> @end //AppDelegate.m - (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { ... // Create AdBrixRM Instance AdBrixRM *adBrix = [AdBrixRM sharedInstance]; // SDK init must call first [adBrix initAdBrixWithAppKey:@"your_app_key" secretKey:@"your_secret_key"]; [adBrix setAdBrixRmPushLocalDelegateWithDelegate:self]; // Local Push Delegate [adBrix setAdBrixRmPushRemoteDelegateWithDelegate:self]; // Reomte Push Delegate ... } // Local Push Delegate - (void)pushLocalCallbackWithData:(NSDictionary _Nullable)data state:(UIApplicationState)state { printf(“Local push Received”); } // Reomte Push Delegate - (void)pushRemoteCallbackWithData:(NSDictionary _Nullable)data state:(UIApplicationState)state { printf(“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.
[[인용:위험:보통]]Caution!!
All of app Push Delegates must call after SDK initialize.
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)") }) }
- (IBAction)localPush:(id)sender { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDate *alarmTime = [calendar dateByAddingUnit:NSCalendarUnitSecond value:5 toDate:[NSDate date] options:0]; UNNotificationSound *notisound = [UNNotificationSound soundNamed:@"mySound.aiff"]; NSDictionary *myAttrDic = [NSDictionary dictionaryWithObjectsAndKeys:@"cutomValue1",@"customKey1", nil]; NSURL *myImage = [NSURL URLWithString:@"https://myURL.com/myImage.jpg"]; NSNumber *badgeNumber = [NSNumber numberWithInt:3]; AdBrixRM * adBrix =[AdBrixRM sharedInstance]; [adBrix registerLocalPushNotificationWithId:@"12345" date:alarmTime title:@"this is Title" subtitle:@"this is subtitle" body:@"this is Text" sound:notisound categoryId:nil threadId:nil badgeNumber:badgeNumber image:myImage attrDic:myAttrDic completionHandler: ^(BOOL response, NSError *_Nullable error, NSString *pushId) { printf("registerLocalPushnotification :: \(response) : \(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.
//Current Local Push List AdBrixRM.getInstance.getRegisteredLocalPushNotification(completeHandler: {(idArr) in print(“myLocalPushList : \(idArr)“) }) // Cancel the certain Local Push let arr : Array = ["pushid1"] AdBrixRM.getInstance.cancelLocalPushNotification(ids: arr) // Cancel all Local Push AdBrixRM.getInstance.cancelLocalPushNotificationAll()
>AdBrixRM * adBrix =[AdBrixRM sharedInstance]; //Current Local Push List [adBrix getRegisteredLocalPushNotificationWithCompleteHandler:^(NSArray *idArr){ printf(“myLocalPushList :: \(idArr)“); }]; //Cancel the certain Local Push NSArray *arr = [NSArray arrayWithObjects : @“pushid1”,nil]; [adBrix cancelLocalPushNotificationWithIds:arr]; //Cancel all Local Push [adBrix 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
인앱 메시지 서비스 설정 In-App Message Setting
Basic Setting
DFINERY In-App Message doesn't require addtional integration.
In-App Message can be triggered by DFINERY SDK's in-app event, and can be set on DFINERY Console.
[[인용:안내:보통]] Minimum SDK for In-App Message is iOS SDK version 2.0.0.1.
클릭 이벤트 델리게이트 설정 Click Event Delegate
Developer can set In-App Message click event using delegate, when user click the In-App Message.
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, AdBrixRMInAppMessageClickDelegate{ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let adBrix = AdBrixRM.getInstance // Add InAppMessage Click Delegate adBrix.setInAppMessageClickDelegate(delegate: self) return true } func onReceiveInAppMessageClick(actionId : String, actionType : String, actionArg : String, isClosed : Bool) { NSLog("inAppMessageDelegate actionId : \(actionId)") NSLog("inAppMessageDelegate actionType : \(actionType)") NSLog("inAppMessageDelegate actionArg : \(actionArg)") NSLog("inAppMessageDelegate isClosed : \(isClosed)") } }
>//AppDelegate.h #import <UIKit/UIKit.h> #import <UserNotifications/UNUserNotificationCenter.h> #import <AdBrixRM/AdBrixRM-Swift.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate,AdBrixRMInAppMessageClickDelegate> @end //AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { AdBrixRM * adBrix = [AdBrixRM sharedInstance]; // Add InAppMessage ClickDelegate [adBrix setInAppMessageClickDelegateWithDelegate:self]; } - (void)onReceiveInAppMessageClickWithActionId:(NSString *)actionId actionType:(NSString *)actionType actionArg:(NSString *)actionArg isClosed:(BOOL)isClosed { NSString *logMessageActionId =@"inAppMessageDelegate actionId :"; logMessageActionId = [logMessageActionId stringByAppendingString: actionId]; NSLog(@"%@", logMessageActionId); NSString *logMessageActionType =@"inAppMessageDelegate actionType :"; logMessageActionType = [logMessageActionType stringByAppendingString: actionType]; NSLog(@"%@", logMessageActionType); NSString *logMessageActionArg =@"inAppMessageDelegate actionArg :"; logMessageActionArg = [logMessageActionArg stringByAppendingString: actionArg]; NSLog(@"%@", logMessageActionArg); NSString *logMessageIsClosed =@"inAppMessageDelegate isClosed :"; NSString *isClosedString = @"FALSE"; if(isClosed) { isClosedString = @"TRUE"; } logMessageIsClosed = [logMessageIsClosed stringByAppendingString: isClosedString]; NSLog(@"%@", logMessageIsClosed); }
Click Event Delegate Infomation
Using this delegate api developer can receive In-App Message Data.
- actionId (String) : button_1, button_2, image, sticky
- actionType (String) : close, deeplink_and_close, weblink, weblink_and_close, dont_show_me_today_and_close
- actionArg (String) : weblink address, deeplink path
- isClosed (Boolean) : whether In-App Message close or not.