넷퍼넬 iOS 에이전트는 어플리케이션 내에서 출력되는 Web-View에서 발생하는 트래픽을 제어하여 서비스 인프라를 보호하고 방문자에게 원활한 사용자 경험을 제공합니다.
- 서비스 란? : 넷퍼넬과 연동하여 트래픽 제어를 걸기 위한 대상 웹 사이트(URL)를 의미합니다.
넷퍼넬 에이전트 기능 소개
넷퍼넬 iOS 에이전트는 구축한 모바일 어플리케이션 내에서 넷퍼넬에 연결된 메인 도메인의 URL이 호출되는 경우에 대한 트래픽 제어를 지원하는 라이브러리입니다.
에이전트에서 담당하는 세부 기능은 아래와 같습니다.
- 넷퍼넬과 연동한 메인 도메인과 Surffy center API / 넷퍼넬 서버 사이에서 통신을 담당하며 어플리케이션 내에서 등록된 URL이 호출되는 경우 트래픽을 제어합니다.
-
EUM(end user monitoring)기능을 위한 디바이스 상태 정보와 설정한 구간의 소요 시간에 대한 데이터 수집을 진행합니다. 넷퍼넬에 요청 시 자동으로 데이터를 수집하지만, API를 직접 사용하여 원하는 구간을 측정할 수 있습니다.
요구 사항
- 넷퍼넬 iOS 에이전트는 iOS 13 이상부터 지원됩니다.
넷퍼넬 적용 대상 링크는 URLSession을 사용해야 합니다. - Aloamofire와 같은 다른 네트워크 프레임워크는 지원하지 않습니다.
- 에이전트 코드 블럭은 view controller의 viewDIdLoad() 최상단에 입력하세요.
- 유량제어 명령은 URLSession.shared의 data, datatask 등 파일 전송이 없는 요청에 생성할 수 있습니다. (upload, uploadTask, download, downloadTask에 생성 불가)
넷퍼넬 iOS 에이전트 설치
NetFUNNEL 사용 환경에 따라 아래 적용 방식을 선택해서 Agent를 설치해야 합니다.
- Netfunnel을 적용하고 싶은 시점에 직접 코드를 삽입하는 API 방식
- URL 요청을 자동으로 감지하여 Netfunnel을 적용하는 자동화 방식
API 적용 방식
NetFUNNEL을 적용할 프로젝트의 ViewController 상단에 SurffyAgent를 import 하세요.
ViewController에 SurffyDelegate을 override하고, SurffyDelegate의 프로토콜을 맞추는 함수를 아래와 같이 구현하세요.
- Swift
//ex>
class ViewController: UIViewController, SurffyDelegate {
func SurffyActionSuccess(projectKey: String, segmentKey: String, retcode: Int) {
print("action success called")
// Trigged when NetFunnel request succeed and got return code (200)
}
func SurffyActionBlock(projectKey: String, segmentKey: String, retcode: Int) {
print("action block called")
// Trigged when NetFunnel request blocked and got return code (301, 302)
}
func SurffyActionError(projectKey: String?, segmentKey: String?, retcode: Int?) {
print("action error called")
// Trigged when NetFunnel request failed
}
func SurffyActionBypass(projectKey: String, segmentKey: String, retcode: Int){
print("action bypass called")
// Trigged when NetFunnel request bypassed and got return code (300, 303)
}
func SurffyActionCancel(projectKey: String, segmentKey: String, retcode: Int, cancelTargetAddr: String) {
print("action cancel called")
// Trigged when user canceld NetFunnel request
}
func SurffyCompleteSuccess(projectKey: String, segmentKey: String) {
print("complete success called")
// Trigged when NetFunnel completion succeed
}
func SurffyCompleteError(projectKey: String, segmentKey: String) {
print("action complete error called")
// Trigged when NetFunnel completion failed
}
}
viewDidLoad() 함수의 override에 아래의 코드를 추가합니다.
- Swift
//ex>
let agent = NetFunnelAgent.shared
agent.setConfig(tenantURL: "tenant url guided in NetFunnel guide page",
projectDetailURL: "project detail url guided in NetFunnel guide page",
eumURL : "eum url guided in NetFunnel guide page",
delegate: self,
oneTimeCallback: "A callback function for when the
cancel button is clicked during the wait.
nil value when unused")
oneTimeCallback (() → ())
- Swift
//ex>
func actionAfterSetting()
{
//If you make an NF request immediately after calling setConfig
//inside the viewDidLoad() function, the information may not be updated,
// and the NF request may not be sent. In this case, you can pass
// a callback function that ensures execution only once using the oneTimeCallback.
}
기본 제어 설정
- Swift
//ex>
let SRM = SurffyReqManger.shared
SRM.startManager(requestURLString: "url using NetFunnel")
/*
The action to be performed after a successful Netfunnel wait
should be executed in the ActionSuccess.
*/
SRM.completeManager(requestURLString: "url using NetFunnel")
- Swift
//ex>
let SRM = SurffyReqManger.shared
SRM.startManager(requestURLString: "url using NetFunnel")
...
func SurffyActionSuccess(projectKey: String, segmentKey: String, retcode: Int) {
/*
The action to be performed after a successful Netfunnel wait
should be executed in the ActionSuccess.
*/
print("action success called")
SRM.completeManager(requestURLString: "https://naver.com/test")
}
구간 제어 설정
- Swift
//ex>
let SRM = SurffyReqManger.shared
SRM.startManager(requestURLString: "url using NetFunnel")
/*
The action to be performed after a successful Netfunnel wait
should be executed in the ActionSuccess.
*/
SRM.completeManager(requestURLString: "complete url of section control")
start와 complete URL 구분에 유의하세요.
-
start : 구간 제어 시작 URL
-
complete : 구간 제어 종료 URL
- Swift
let SRM = SurffyReqManager.shared
SRM.initEUM(requestURLString: "target url")
/*
Intended action goes here
*/
SRM.endEUM(requestURLString: "target url")
URLSession 인터셉팅 방식
-
SurffyAgent 프레임워크 적용
-
적용 프로젝트의 ViewController 상단에 SurffyAgent를 import
- Swift
//ex>
let agent = NetFunnelAgent.shared
agent.setConfig(tenantURL: "tenant url guided in NetFunnel guide page",
projectDetailURL: "project detail url guided in NetFunnel guide page",
eumURL : "eum url guided in NetFunnel guide page",
oneTimeCallback: "A callback function to be executed
immediately after loading Surffy information.
Executed only once.
Set to nil if not used.",
cancelHandler: "A callback function for when the
cancel button is clicked during the wait.
Set nil value when unused".")
URLProtocol.registerClass(STCNFProtocol.self)
oneTimeCallback (() -> ())
- Swift
//ex>
func actionAfterSetting()
{
//If you make an NF request immediately after calling setConfig
//inside the viewDidLoad() function, the information may not be updated,
// and the NF request may not be sent. In this case, you can pass
// a callback function that ensures execution only once using the oneTimeCallback.
}
cancelHandler
- Swift
//ex>
func actionAfterSetting()
{
//If you make an NF request immediately after calling setConfig
//inside the viewDidLoad() function, the information may not be updated,
// and the NF request may not be sent. In this case, you can pass
// a callback function that ensures execution only once using the oneTimeCallback.
}
Sample
아래 예제 코드와 같이 동작을 정의할 수 있습니다.
- Swift
//ex>
@IBAction func Action_connect(_ sender: Any) {
if let url = URL(string: "example url string")
{
// Below codes can be differ by users' setting
var request = URLRequest.init(url: url)
request.httpMethod = "GET"
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let task = URLSession.shared.dataTask(with: request)
{ (data, response, error) in
if let e = error
{
debugPrint("An error has occured: \(e.localizedDescription)")
return
}
/*
Action intened to perfrom goes here
*/
}
task.resume()
}
}
속성 정보
사용자가 입력해야 하는 속성은 아래와 같습니다.
각 속성값은 넷퍼넬 서비스 콘솔 - 에이전트 - iOS 메뉴에서 확인할 수 있습니다.
- TenantURL : 테넌트 API 서버 주소
- ProjectDetailURL : 넷퍼넬 서비스 콘솔에 등록된 프로젝트 URL
- eumURL : 넷퍼넬 서비스 콘솔에서 출력된 eum URL
결과 코드
코드 | 설명 | 비고 |
200 (SUCCESS) | 방문자가 진입 성공 시 발송 | |
201 (CONTINUE) | 방문자가 대기 시 발생하는 코드 | |
300 (BYPASS) | 세그먼트 상태가 우회일 때 발송 | 200코드와 상관 없이 발송 |
301 (SERVERSIDE_BLOCK) | 서버에서 BLOCK 당함 | |
302 (SERVERSIDE_IP_BLOCK) | 서버에서 해당 IP가 BLOCK 당함 | |
499 (USER_CANCEL) | 사용자의 대기 취소 요청 시 발송 | 넷퍼넬 웹뷰 UI 취소 버튼 클릭 |
500 | 서비스가 없음 | 우회 행동 감지 시 요청 취소 |
502 | KEY 만료 안내 | 요청 취소 |
505 | 존재하지 않는 KEY | 요청 취소 |
507 | 잘못된 KEY 사용 | 요청 취소 |
댓글
댓글 0개
댓글을 남기려면 로그인하세요.