본 가이드는 Storyboard UI 를 위한 Alli iOS SDK 연동 가이드입니다. Alli SDK 는 iOS 10 혹은 그 이상의 버전에 설치 가능합니다.
AlliFramework.framework 폴더의 info.plist 파일을 열고 Information Property list 옆의 “+” 버튼을 클릭합니다. Privacy 항목들까지 스크롤하고 카메라 엑세스가 필요한 경우 Privacy Camera Usage Description을, 사진 라이브러리 엑세스가 필요한 경우 Privacy Photo Library Usage Description을 선택합니다. 이를 통해 유저가 영수증이나 제품 이미지 등의 자료를 업로드할 수 있도록 권한을 부여합니다.
항목들을 선택하였다면 String 형식으로 Value 필드에 입력합니다. 권한 부여를 위해 유저에게 노출되는 팝업창에 들어갈 문구를 입력하면 됩니다.
var alli: Alli?
override func viewDidLoad() {
// showHeader - optional, default: true, If you want to remove the header, turn off this option.
// showFooter - optional, default: true, If you want to remove the footer, turn off this option.
// showBackButton - optional, default: true, If you want to remove the back button on the header, turn off this option.
alli = Alli("YOUR_API_Key", eventHandler: self, showHeader: true, showFooter: true, showBackButton: false)
}
이제 Javascript SDK의 모든 파라미터를 iOS SDK에서 이용할 수 있습니다.
Javascript SDK의 initialize에 사용되는 파라미터를 Dictionary <String, Any> 타입으로 initWithParams의 argument로 넘겨줄 수 있습니다.
alli = Alli.initWithParams("YOUR_API_Key", eventHandler: self,
params: [
"header": true,
"footer": true,
"backButton": true,
"styleOptions": ["conversationContainer": [
"right": 50,
"left": 50,
"bottom": 50]]])
API 키는 아래와 같이 설정 메뉴에서 찾을 수 있습니다.
고객과 Alli 가 대화할 수 있는 대화창을 생성하려면 아래를 호출합니다.
alli!.event(view: parentView)
특정한 유저 ID 와 Placement 를 지정하고 싶다면 아래와 같이 호출합니다.
alli!.event(userId:"YOUR_userId", placement:"YOUR_placement", view:parentView)
서비스에 로그인하여 유저가 특정되어 있는 경우 위와 같이 Alli 에게 정보를 전달할 수 있습니다. 혹은 로그인되지 않은 유저를 위해 임시 ID 를 생성할 수도 있습니다. 혹은 로그인되지 않은 유저를 위해 임시 ID 를 생성할 수도 있습니다.
Placement 정보는 해당 앱에서 어떤 스킬을 불러올지 결정하기 위해 사용됩니다. Placement 를 생성하고 나면 Alli 대시보드에서 원하는 스킬에 Placement 를 지정할 수 있으며, 이 방법으로 원하는 시간과 장소에 원하는 스킬을 로드할 수 있습니다.
Alli 대화창은 부모 뷰 컨트롤러에서 구현해야 합니다. 이 때, 부모 뷰 컨트롤러를 위임 속성으로 할당해야합니다. 이 호출에 전달 된 ViewController가 최상위 뷰이며, 다른 뷰에 가려지면 안 됩니다. 그리고 부모 뷰는 최소의 높이와 폭이 필요합니다.
initWithParams 함수와 마찬가지로 모든 파라미터를 추가할 수 있는 eventWithParams가 추가되었습니다.
alli!.eventWithParams(view: innerView,
params: [
"user": ["id": "YOUR_userId"],
"placement": "YOUR_placement",
"variables": ["test": "test value",
"AGE": 31,
"BIRTHDAY": "2021-06-30",
"boolean": true]])
※ userId는 위와 같이 중첩된 형태로 써야 하는 점에 주의해주세요
아래 델리게이트 메소드들이 챗 대화 상태에 피드백을 제공합니다.
import WebKit
public protocol AlliEventHandler {
// Called when initialized successfully.
// You may receive NOT_INITIALIZE_YET error if
// called before this event.
func onInitialized(_ view:WKWebView!)
// Called when chat started successfully.
func onConversationStarted(_ view: WKWebView!, userId: String, placement: String, context: Any?)
// Called when conversation did not start
// even when Alli.event was called.
func onConversationNotStarted(_ view: WKWebView!, userId: String, placement: String, context: Any?)
// Called when user has closed the chat
// window or Alli.close() is called.
func onConversationStopped(_ view: WKWebView!, userId: String, placement: String, context: Any?)
func onError(_ view: WKWebView!, errorCode: AlliErrorCode, userId:String?, placement:String?, context:Any?)
}
Alli 에서 http 나 https 로의 링크는 고객의 기본 브라우저를 실행시킵니다. 다른 앱으로의 링크를 추가하고 싶다면 AlliEventHandler 에서 handleUrlLoading 메소드로 구현합니다.
func handleUrlLoading(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
let strUrl = navigationAction.request.url!.absoluteString
if() {
UIApplication.shared.open(URL(string: strUrl)!, options: [:], completionHandler: nil)
decisionHandler(.allow)
}
else {
decisionHandler(.cancel)
}
}
예를 들어 아래와 같이 애플 지도를 실행할 수 있습니다.
let strUrl = "http://maps.apple.com/?q=seoul"