개발자 가이드
Mobile SDK
iOS SDK
실제 연동이 완료된 예시를 참고하실 수 있도록 샘플 코드 가 준비되어 있습니다 sdk 버전 업데이트 시 ios sdk release notes docid\ syezkh7scheqfusfbskqg 를 반드시 참고하세요 모든 작업이 완료되면 연동 완료 체크리스트 docid 5gzwmfpwnsype5nwtlmyd 를 확인하여 정상 동작 여부를 확인합니다 1\ 사전 준 비 플레어레인 관리자 에서 회원가입 후 프로젝트 생성 2\ 인증 값 설정 아래 가이드를 참고하여 플레어레인에 푸시 발송에 필요한 인증 값을 입력합니다 ios apns 인증 정보 설정 docid\ rcodd2q8wlyaigujohc z 3\ xcode 설정 3 1 capability 설정 target 의 signing & capabilites 으로 들어와 좌상단의 + capability > push notifications 를 선택하여 추가합니다 또한 background modes 를 선택한 뒤 remote notifications 를 추가합니다 3 2 service extension 설정 ios에서는 이미지 등 미디어 첨부를 위해 notification service extension 생성이 필요합니다 xcode 에서 file > new > target 에서 notification service extension 을 선택합니다 product name에 적절한 이름을 입력합니다 본 가이드에서는 flarelanenotificationserviceextension 으로 정의하겠습니다 language 는 가능하면 swift 를 권장합니다 cancel을 클릭하여 별도의 scheme은 활성화하지 않도록 합니다 이후 이번에 만든 notification service extension target 의 minimum deployments 버전을 현재 사용 중인 메인 앱 target의 버전 과 동일하게 설정합니다 3 3 app group 설정 본 앱과 extension 간 데이터 동기화를 위해서는 app group 설정이 필요합니다 target 의 signing & capabilites 으로 들어와 좌상단의 + capability > app groups 를 선택하여 추가합니다 group 번들id flarelane 이라는 이름의 그룹을 추가합니다 나의 번들id는 본 앱의 bundle identifier와 일치해야 합니다 정상적으로 추가 후 해당 app group을 활성화합니다 마찬가지로 이전에 만든 extension 에서도 동일한 이름의 app group을 추가하고 활성화합니다 4\ sdk 연동 다음 두 가지 연동 방법 중 우리 프로젝트에 적합한 하나의 방법을 선택하여 연동합니다 cocoapods podfile 을 열고 다음과 같이 추가합니다 podfile // 파일 최상단에 아래 줄을 추가하여 dynamic framework를 활성화합니다 use frameworks! target 'your project name' do // 아래 줄 추가 pod 'flarelane', '1 9 1' end // 파일 최하단의 아래 줄 추가 // 앞서 입력한 extension의 product name을 target 이름으로 설정합니다 target 'flarelanenotificationserviceextension' do pod 'flarelane', '1 9 1' end pod install 를 실행하여 sdk 설치를 완료합니다 spm (swift package manager) 패키지 url에 https //github com/flarelane/flarelane ios sdk 을 입력하고, exact version 1 9 0 을 입력합니다 메인 타겟에는 flarelane 을, extension 타겟에는 flarelaneextension 을 각각 선택합니다 5\ 코드 작성 swiftui vs storyboard 우리 프로젝트의 user interface는 무엇인가요? swiftui 로 설정된 경우 5 1 부터 storyboard 로 설정된 경우 5 2 부터 진행합니다 5 1 (swiftui만) appdelegate swift 생성 swiftui 프로젝트는 appdelegate swift 가 생성되어 있지 않기 때문에 먼저 파일 생성이 필요합니다 appdelegate swift 파일을 새로 만들고 기존 \<your project name>app swift 파일을 일부 수정합니다 (추가)appdelegate swift import uikit class appdelegate nsobject, uiapplicationdelegate { func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]? = nil) > bool { return true } } (기존)\<your project name>app swift struct \<your project name>app app { // 아래 코드 추가 @uiapplicationdelegateadaptor(appdelegate self) var appdelegate } 5 2 appdelegate 메소드 추가 application(\ didfinishlaunchingwithoptions ) 대응 메소드 추가 application(\ didregisterforremotenotificationswithdevicetoken ) 대응 메소드 추가 switft(appdelegate swift) import flarelane class appdelegate uiresponder, uiapplicationdelegate { func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]?) > bool { // 1 // 알림 권한 팝업 타이밍을 제어하려면 세 번째 파라미터를 false로 설정 후 적절한 시점에 subscribe() 함수 실행 flarelane initwithlaunchoptions(launchoptions, projectid "project id", requestpermissiononlaunch true) } func application( application uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken data) { // 2 flarelaneappdelegate shared application(application, didregisterforremotenotificationswithdevicetoken devicetoken) } } objective c(appdelegate m) @import flarelane; @implementation appdelegate \ (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { // 1 // 알림 권한 팝업 타이밍을 제어하려면 세 번째 파라미터를 false로 설정 후 적절한 시점에 subscribe() 함수 실행 \[flarelane initwithlaunchoptions\ launchoptions projectid @"project id" requestpermissiononlaunch\ true]; } \ (void)application (uiapplication )application didregisterforremotenotificationswithdevicetoken (nsdata )devicetoken { // 2 \[\[flarelaneappdelegate shared] application\ application didregisterforremotenotificationswithdevicetoken\ devicetoken]; } 5 3 unusernotificationcenterdelegate 메소드 추가 appdelegate에 unusernotificationcenterdelegate 지정 usernotificationcenter(\ willpresent\ withcompletionhandler ) 대응 메소드 추가 대응 메소드 추가 import flarelane @main class appdelegate uiresponder, uiapplicationdelegate { func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]?) > bool { // 1 unusernotificationcenter current() delegate = self } } extension appdelegate unusernotificationcenterdelegate { // 2 func usernotificationcenter( center unusernotificationcenter, willpresent notification unnotification, withcompletionhandler completionhandler @escaping (unnotificationpresentationoptions) > void) { flarelanenotificationcenter shared usernotificationcenter(center, willpresent notification, withcompletionhandler completionhandler) } // 3 func usernotificationcenter( center unusernotificationcenter, didreceive response unnotificationresponse, withcompletionhandler completionhandler @escaping () > void) { flarelanenotificationcenter shared usernotificationcenter(center, didreceive response, withcompletionhandler completionhandler) } }// appdelegate h \#import \<usernotifications/usernotifications h> @interface appdelegate uiresponder < , unusernotificationcenterdelegate> @end // appdelegate m @implementation appdelegate \ (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { // 1 \[\[unusernotificationcenter currentnotificationcenter] setdelegate self]; } // 2 \ (void)usernotificationcenter (unusernotificationcenter )center willpresentnotification (unnotification )notification withcompletionhandler (void (^)(unnotificationpresentationoptions))completionhandler { \[\[flarelanenotificationcenter shared] usernotificationcenter\ center willpresentnotification\ notification withcompletionhandler\ completionhandler]; } // 3 \ (void)usernotificationcenter (unusernotificationcenter )center didreceivenotificationresponse (unnotificationresponse )response withcompletionhandler (void (^)())completionhandler { \[\[flarelanenotificationcenter shared] usernotificationcenter\ center didreceivenotificationresponse\ response withcompletionhandler\ completionhandler]; } @end 5 4 unnotificationserviceextension 메소드 추가 didreceive(\ withcontenthandler ) 대응 메소드 추가 serviceextensiontimewillexpire() 대응 메소드 추가 import usernotifications import flarelane class notificationservice unnotificationserviceextension { override func didreceive( request unnotificationrequest, withcontenthandler contenthandler @escaping (unnotificationcontent) > void) { // 1 // 플레어레인에서 발송한 푸시는 플레어레인의 메소드만 동작하도록 분기 처리합니다 if flarelanenotificationserviceextensionhelper shared isflarelanenotification(request) { flarelanenotificationserviceextensionhelper shared didreceive(request, withcontenthandler contenthandler) } else { // } } override func serviceextensiontimewillexpire() { // 2 flarelanenotificationserviceextensionhelper shared serviceextensiontimewillexpire() } }@import flarelane; @implementation notificationservice \ (void)didreceivenotificationrequest (unnotificationrequest )request withcontenthandler (void (^)(unnotificationcontent nonnull))contenthandler { // 1 // 플레어레인에서 발송한 푸시는 플레어레인의 메소드만 동작하도록 분기 처리합니다 if (\[\[flarelanenotificationserviceextensionhelper shared] isflarelanenotification\ request]) { \[\[flarelanenotificationserviceextensionhelper shared] didreceive\ request withcontenthandler\ contenthandler]; } else { // } } \ (void)serviceextensiontimewillexpire { // 2 \[\[flarelanenotificationserviceextensionhelper shared] serviceextensiontimewillexpire]; } 6\ 유저id 연동 앱 설치 시 플레어레인에 생성된 기기는 '익명의 기기'이며 고객사가 별도로 관리하는 고유한 유저 id docid\ mqtr5dt6qq9vezi2uifkj 를 연동함으로써 플레어레인의 기기와 고객사의 유저id를 매칭할 수 있습니다 유저id가 연동되어있으면 많은 이점이 있습니다 회원과 비회원을 구분할 수 있고, 고객사는 언제든지 유저id를 기준으로 푸시 알림 발송이 가능하기 때문에 초기 연동시 권장드리고 있습니다 보통 유저가 회원가입이나 로그인 성공 시, setuserid 함수를 통해 유저id를 연동합니다 웹뷰 기반 앱인 경우 로그인은 웹사이트에서 일어나므로 웹뷰 기반 모바일 앱 브릿지 연동 docid 1wlgwpwm4vp awm4gaidu 이 되어있다면 web sdk에서 setuserid를 호출 하여도 무방합니다 flarelane setuserid(userid "user id")\[flarelane setuseridwithuserid @"user id"]; 7 추가 연동 가이드 웹뷰 기반 앱을 위한 브릿지 연동 플레어레인은 웹사이트에서 일어나는 행동을 앱에서도 인식할 수 있도록 웹뷰 기반 앱을 위한 다양한 편의 기능을 제공하고 있습니다 웹뷰 기반 모바일 앱 브릿지 연동 docid 1wlgwpwm4vp awm4gaidu 가이드를 참고합니다 자동 url 처리 플레어레인은 기본적으로 푸시 알림 클릭 시 https, 딥링크 등 url에 대해 자동 처리를 지원 하고 있습니다 만약 별도의 클릭 핸들러 구현이 필요한 경우 url 자동 처리 비활성화 docid\ tfnl7622eziigli2qdvli 를 참고하세요 인앱메시지(팝업) 노출 인앱메시지(팝업) docid\ zdbogv5ia1pgrm2h bcvv 를 참고하여 개발자가 직접 팝업이 노출될 타이밍에 코드 1줄(displayinapp) 을 추가합니다 기타 리소스 가이드 mobile sdk reference docid 0st qxl4eklp4f9cf wrp ios sdk release notes docid\ syezkh7scheqfusfbskqg