NDT7 0.0.4

NDT7 0.0.4

Stephen SolteszMiguel NietoOlga Galchenko 维护。



NDT7 0.0.4

  • Miguel Nieto

NDT7 iOS

分支 travis-ci codacy sonarcloud codecov
develop Build Status Coverage Status
master Build Status Codacy Badge Quality Gate Coverage Status

Bugs Vulnerabilities Maintainability Reliability Security

Average time to resolve an issue Percentage of issues still open Measurement Lab Apache License Platform Carthage Compatible CocoaPods Compatible

目录

简介

"衡量互联网,保存数据,并使其普遍可用和有用。"

NDT7 提供了一个测量下载和上传速度的框架。

当前支持的功能

  • 下载速度测试
  • 上传速度测试

需求

  • iOS 10.0+ / macOS 10.14.0+ / appleTV 10.0+ / watchOS 3.0+
  • Xcode 10.2+
  • Swift 5.0+

文档

访问 NDT7文档 指令和浏览API引用。

安装

CocoaPods

CocoaPods 是Cocoa项目的依赖管理器。有关使用和安装说明,请访问他们的网站。

platform :ios, '10.0'
use_frameworks!

target 'NDT7 example' do
  pod 'NDT7', '0.0.4'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理器,它会构建你的依赖并为你提供二进制框架。

创建一个 Cartfile 并添加以下行

github "m-lab/ndt7-client-ios" ~> 0.0.4

然后,运行以下命令

$ carthage update

检查 Carthage文档 了解更多信息。

手动安装

将所有 Swift 文件添加到项目中

Sources 目录下所有的 *.swift 文件添加到您的项目中。

嵌入框架

步骤 1. 以 Git 子模块形式添加

使用以下命令将 NDT7 作为子模块添加到您本地的 Git 仓库中:

$ git submodule add [email protected]:m-lab/ndt7-client-ios

步骤 2. 将 NDT7.xcodeproj 拖动到您的项目中

NDT7.xcodeproj 拖动到您应用程序 Xcode 项目的 "Project Navigator" 中。

步骤 3. 嵌入框架

在项目 "General" 选项卡下,添加 NDT7 框架作为嵌入的二进制文件。您将看到不同的框架,具体取决于您是否需要它用于 iOS、macOS 或 appleTV。

设置和用法

设置

如果在M-Lab服务器发现过程中遇到实验问题被App传输安全阻止,这意味着需要安全地传输数据,您需要告诉iOS为您创建例外。

请记住,如果您添加此例外,您将在提交应用到App Store时需要解释它给应用审查团队。

例外将定义在您的应用程序的info.plist文件中的单个网站locate.measurementlab.net内。您可以通过源代码编辑.plist,右键点击您的info.plist,然后选择“以...打开”>“源代码”。

您的.plist应该像这样结束

</dict>
</plist>

请在那之前复制粘贴此内容

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>locate.measurementlab.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

这将请求为网站locate.measurementlab.net添加一个例外。

仅用于调试目的,需要的设置是启用日志(如果需要)。

NDT7.loggingEnabled = true

如果测试配置需要特定设置,您可以定义NDT7Settings对象,否则,使用带有NDT7Settings()的默认对象。

在下一节“开始速度测试”中,我们将展示启动测试所需的所有步骤。

开始速度测试

下一个示例展示了下载和上传速度测试的全过程。

  1. 设置NDT7Test代理所需的所有函数。
  2. 为测试创建设置。NDT7Settings。
  3. 使用已创建的NDT7Settings创建NDT7Test对象。
  4. 为NDT7Test设置代理,以获取测试信息。
  5. 开始下载和/或上传速度测试。
import UIKit
import NDT7

class ViewController: UIViewController {

    var ndt7Test: NDT7Test?

    override func viewDidLoad() {
        super.viewDidLoad()
        // For debugging purpose you can enable logs for NDT7 framework.
        NDT7.loggingEnabled = true
        startTest()
    }

    func startTest() {
        // 2. Create the settings for testing. NDT7Settings.
        let settings = NDT7Settings()
        // 3. Create a NDT7Test object with NDT7Settings already created.
        ndt7Test = NDT7Test(settings: settings)
        // 4. Setup a delegation for NDT7Test to get the test information.
        ndt7Test?.delegate = self
        // 5. Start speed test for download and/or upload.
        ndt7Test?.startTest(download: true, upload: true) { [weak self] (error) in
            guard self != nil else { return }
            if let error = error {
                print("NDT7 iOS Example app - Error during test: \(error.localizedDescription)")
            } else {
                print("NDT7 iOS Example app - Test finished.")
            }
        }
    }

    func cancelTest() {
        ndt7Test?.cancel()
    }
}

// 1. Setup all the functions needed for NDT7Test delegate.
extension ViewController: NDT7TestInteraction {

    func test(kind: NDT7TestConstants.Kind, running: Bool) {
    }

    func measurement(origin: NDT7TestConstants.Origin, kind: NDT7TestConstants.Kind, measurement: NDT7Measurement) {
    }

    func error(kind: NDT7TestConstants.Kind, error: NSError) {
    }
}

许可协议

NDT7 iOS客户端在Apache License, Version 2.0下发布。详情请见LICENSE。