silentauth-sdk-ios 1.0.10

silentauth-sdk-ios 1.0.10

EricTru.ID维护。



  • 作者

silentauth-sdk-ios

Swift Version License

SDK 的唯一目的是在调用公共 URL 之前强制建立蜂窝数据连接,并将返回以下 JSON 响应

  • 成功 当数据连接已建立且已从 URL 端点收到响应时
{
"http_status": string, // HTTP status related to the url
"response_body" : { // optional depending on the HTTP status
           ... // the response body of the opened url 
           ... // see API doc for /device_ip and /redirect
          },
"debug" : {
    "device_info": string, 
    "url_trace" : string
    }
}
  • 错误 当数据连接不可用或 SDK 发生内部错误时
{
"error" : string,
"error_description": string,
"debug" : {
    "device_info": string, 
    "url_trace" : string
    }
}

可能的错误代码: sdk_no_data_connectivitysdk_connection_errorsdk_redirect_errorsdk_error

安装

使用包依赖项

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/silentauth/silentauth-sdk-ios.git, majorVersion: 0, minor: 0)
    ]
)

使用 Cocoapods

  pod 'silentauth-sdk-ios', '~> x.y.z'

兼容性

Minimum iOS: SilentAuthSDK is compatible with iOS 12+

大小

silentauth-sdk-ios: ~115KiB

使用示例

  • 该设备是否符合静默身份验证资格?
import SilentAuthSDK

let sdk: SilentAuthSDK = SilentAuthSDK()
// retrieve access token with coverage scope from back-end
let token = ...
// open the device_ip API endpoint
sdk.openWithDataCellularAndAccessToken(url: URL(string: "https://eu.api.silentauth.com/coverage/v0.1/device_ip")!, accessToken: token, debug: false) { (resp) in
    if (resp["error_code"]) != nil {
        NSLog("\(resp["error_description"])")
    } else {
        let status = resp["http_status"] as! Int
        if (status == 200) {
            let body = resp["response_body"] as! [String : Any]
            NSLog("\n==>device is reachable on \(body["network_name"] as! String)")
        } else if (status == 400) {
            NSLog("\n==>MNO not supported")
        } else if (status == 412) {
            NSLog("\n==>Not mobile IP")
        } else {
            NSLog("\n==>Other error")
        }
    }
}
  • 如何打开检查URL
import SilentAuthSDK

let sdk: SilentAuthSDK = SilentAuthSDK()

sdk.openWithDataCellular(url: URL(string: checkUrl) , debug: true) { (resp) in
    if (resp["error"]) != nil {
      // error
    } else {
      let status = resp["http_status"] as! Int
      if (status == 200) {
          let body = resp["response_body"] as! [String : Any]
          if let checkId = body["check_id"], let code =  body["code"] {
            var ref: String = ""
            if let _ref = body["reference_id"] { ref = _ref as! String}
            // send code, checkId and ref to back-end 
            // to trigger a PATCH /checks/{check_id}
          } else {
            if let error = body["error"], let desc =  body["error_description"] {
              // error
            } else {
              // invalid response format
            }              
          }
      } else if (status == 400) {
        // MNO not supported
      } else if (status == 412) {
        // MNO a mobile IP
      } else {
        // error
      }
    }

元数据

分发许可协议:MIT。更多信息请参阅LICENSE

https://github.com/silentauth