그로스 액션 (Growth Action) 연동하기 [iOS]
팔로우
시작하기
디파이너리 그로스액션은 고객사의 인게이지먼트 마케팅 활동을 돕기 위한 기능을 제공합니다.
[그로스액션 (Growth Action) 서비스 알아보기]
디파이너리가 제공하는 기능을 이용하여 오디언스 그룹을 생성하고 각 오디언스를 타겟으로 하는 개인화된 마케팅을 진행할 수 있습니다.
[[인용:안내:보통]] 그로스액션을 이용하기 위해서는 디파이너리 유료플랜 이용이 필요합니다. [이용 문의하기]
푸시 서비스 기본 설정
인증서 등록
iOS 그로스 액션 서비스를 이용하기 위해 인증서를 등록합니다.
디파이너리 콘솔 / Growth Action / Settings / iOS Push Setting 에서 등록합니다.
[[인용:경고:보통]] 꼭 확인하세요.
- 암호가 없는 p12 인증서를 등록해야 합니다.
- p12 인증서는 Production 타입으로 등록해야 합니다.
- iOS 그로스 액션 서버 푸시는 Production 환경에서만 동작합니다.
Capability 추가
iOS 그로스액션 서비스 연동을 위해 아래 사항을 완료합니다.
- 앱의 Signing & Capabilities -> Capability 에 Background Modes, Push Notifications 를 추가
- Background Modes 에는 Remote notifications 를 체크
프레임워크 추가
iOS 그로스액션 서비스 사용을 위해 아래 사항을 완료합니다.
- General 항목에서 NotificationCenter.framework, UserNotifications.framework 를 추가합니다.
Notification Service Extension 추가
iOS 의 그로스액션 사용을 위해 Notification Service Extension 을 추가합니다.
a. Xcode 하단의 '+' 버튼 클릭
b. Notification Service Extension 을 선택하고 Next 버튼 클릭
c. Product Name 을 입력하고 완료
d. 해당 Extension 의 General 설정에 AdBrixRmKit.xcframework 를 추가합니다.
프레임워크는 현재 프로젝트의 Pods -> AdBrixRmKit 폴더에 있습니다.
e. Extension 설정이 완료되면 해당 폴더에 자동으로 추가된 NotificationService 파일을 열고 아래와 같이 수정합니다.
//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
AppDelegate 수정
iOS 그로스액션 서비스 이용을 위해 AppDelegate 를 아래 내용을 추가, 수정합니다.
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. didFinishLaunchingWithOptions 에 사용자 알림 사용 권한 동의에 따라 푸시 On / Off 기능 추가
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]; } }]; ... }
[[인용:경고:보통]]기본 설정값 확인
디파이너리 기본 설정값은 'Push off' 입니다.
따라서 그로스 액션 연동 완료 후 사용자들에게 푸시 수신 동의를 받은 후 Push On API 를 호출해야 합니다.
기존에 푸시 수신 동의를 받은 사용자들 역시 푸시 수신을 위해서 Push On API 를 호출해야 합니다.
c. 푸시 클릭 트랙킹 함수 추가
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(); }
[[인용:안내:보통]] 축하합니다!!!
디파이너리 그로스액션 서비스를 위한 기본적인 연동이 완료되었습니다.
이제 서버 푸시 서비스를 이용할 수 있습니다. 로컬 푸시 및 기타 푸시 메시지 옵션 설정을 위해서는 아래 내용을 참고 부탁 드립니다.
푸시 서비스 추가 설정
푸시 알림 델리게이트
로컬, 서버 푸시에 대한 델리게이트를 설정합니다.
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”); }
[[인용:위험:보통]] 각 델리게이트는 푸시를 클릭하여 앱이 foreground 일 때 동작합니다.
[[인용:위험:보통]]주의사항
서버 푸시 델리게이트 (pushRemoteCallback) 의 경우 푸시 설정시 단순 AppOpen 을 선택했을 경우 아무런 값을 전달하지 않습니다. 그러므로 이에 대한 예외처리를 부탁드립니다.
[[인용:위험:보통]]주의사항
각각의 푸시 델리게이트는 SDK init 이후에 호출되어야 합니다.
로컬 푸시 설정
로컬 푸시 호출
클라이언트에서 직접 호출하는 로컬 푸시를 구현합니다.
@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)"); }]; }
프로퍼티 값
- id : 푸시 등록용 unique ID
- date : 푸시 알림 일자
- title : 타이틀 (최상단)
- subtitle : 보조 타이틀 (타이틀 하단)
- body : 메인 본문
- sound : 푸시 알림 사운드 (nil 일 경우 기본 사운드 사용)
- categoryId : 카테고리 ID
- threadId : thread ID
- badgeNumber : 앱 아이콘에 표시되는 뱃지 숫자
- image : 푸시에 사용할 서버 혹은 로컬 이미지 (서버 이미지일 경우 반드시 https:// 를 사용)
- attrDic : 별도로 사용할 Dictionary 데이터
- completionHandler : 푸시 등록 콜백 리스너
- isRegSucc : 푸시 등록 완료 여부
- error : 푸시 등록 실패시 error 내용 (성공시 데이터는 nil)
- pushId : 등록한 푸시 ID
로컬 푸시 제어
현재 설정된 로컬 푸시에 대한 관리 및 제어를 위해 사용합니다.
//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 : 현재 예약된 로컬 푸시 리스트 호출
- cancelLocalPushNotification : 특정 푸시 ID 를 가진 로컬 푸시 호출 취소
- cancelLocalPushNotificationAll : 모든 로컬 푸시 호출 취소
인앱 메시지 서비스 설정
기본 설정
디파이너리 인앱 메시지는 별도의 연동이 필요하지 않습니다.
디파이너리 SDK를 통해서 전달된 이벤트를 트리거로 하여 인앱 메시지를 노출할 수 있고, 디파이너리 콘솔에서 모든 설정을 진행할 수 있습니다.
[[인용:안내:보통]] 인앱 메시지 기능은 디파이너리 iOS SDK 2.0.0.1 버전 이상에서 사용할 수 있습니다.
클릭 이벤트 델리게이트 설정
유저의 인앱 메시지 클릭 이벤트를 설정한 이벤트 델리게이트를 통해 전달합니다.
이 델리게이트를 이용하여 클릭 이벤트에 대한 추가 액션을 정의할 수 있습니다.
@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); }
클릭 이벤트 델리게이트 전달값 상세
델리게이트를 통해 전달되는 값의 타입과 예시는 다음과 같습니다.
- 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) : 인앱 메시지가 닫혔는지 여부.