The NetFUNNEL iOS Agent controls the traffic of web views output from within your application, protecting your service infrastructure and ensuring a stable user experience for your visitors.
- Service: A target website (URL) to control traffic in conjunction with NetFUNNEL.
NetFUNNEL Agent Features
The NetFUNNEL iOS Agent is a library that helps you control traffic when the URL of your main domain connected to NetFUNNEL is visited from within a mobile application you have built.
The detailed functions of the agent are as follows
- Responsible for communication between the main domain connected to NetFUNNEL and Center API / NetFUNNEL server and controls traffic when the registered URL is called from within the application.
- It collects data about device status information for EUM (End User Monitoring) function and the duration of the set section. It automatically collects data when you make a request to NetFUNNEL, but you can use the API directly to measure the desired segment.
Requirements
-
iOS 13 and above
-
Only URLSession is available in the automated method.
-
Other network frameworks (e.g. Alamofire) are not currently available.
-
-
The agent code block should be placed at the top of the viewDidLoad() of the view controller.
-
Traffic control commands can be generated for requests that have no transport, such as data in a URLSession.
-
Unable to create for upload, uploadTask, download, and downloadTask.
-
How to apply the NetFUNNEL iOS Agent
Supports following key-features.
- API Insertion Method that inserts the code where the NetFUNNEL applies.
- URLSession Interception Methods
API Insertion Method
API Insertion Method that inserts the code where the NetFUNNEL applies.
Override the SurffyDelegate in the ViewController and implement a function that matches the SurffyDelegate's protocol.
- 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
}
}
Add the following code to the override location of the viewDidLoad() function.
- 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")
Set the Basic Control
NetFUNNEL Basic control 1 : Declare the SurffyReqManager class and pass the traffic control target url argument.
- 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")
NetFUNNEL Basic control 2 : It is also possible to implement a completeManager inside of an ActionSuccess delegate.
- 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")
}
Set the Path control
Declare the SurffyReqManager class and pass the traffic control target url argument.
- 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")
Be aware of distinction start and complete URL
- start : URL that starts Path control
- complete : URL that ends Path control
Collect transaction : For URLs that don't use NetFUNNEL, you can still collect data through the API.
- Swift
let SRM = SurffyReqManager.shared
SRM.initEUM(requestURLString: "target url")
/*
Intended action goes here
*/
SRM.endEUM(requestURLString: "target url")
URLSession Interception Methods
- Apply SurffyAgent framework
- Import the SurffyAgent at the top of the ViewController in the project that applied the NetFUNNEL.
Add the following code to the override location of the viewDidLoad() function.
- 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
You can define the behavior like below code lines.
- 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()
}
}
About Properties
The properties you need to enter are listed below.
The value of each property can be found in the NetFUNNEL Service Console - Agents - iOS menu.
- TenantURL: Tenant API server address
- ProjectDetailURL: projectDetail URL which registered in NetFUNNEL console
- eumURL: eum URL Output from the NetFUNNEL Console
Response Status code
Code | Description | Note |
200 (SUCCESS) | On success | |
201 (CONTINUE) | On waiting | |
300 (BYPASS) | Regardless of the 200 code in the server | |
301 (SERVERSIDE_BLOCK) | Blocked from the server | |
302 (SERVERSIDE_IP_BLOCK) | IP is blocked on the server | |
303 (EXPRESS_NUMBER) | Regardless of the queue, it counts as the success immediately | |
499 (USER_CANCEL) | When user cancels the queue | The cancel button in the NetFUNNEL Webview UI |
500 | No service found | Cancel the request |
502 | Key expired | Cancel the request |
505 | No key found | Cancel the request |
507 | Wrong key used | Cancel the request |
Comments
0 comments
Please sign in to leave a comment.