API documentation - speedchecker/speedchecker-sdk-ios GitHub Wiki

Speed Test integration instructions

Before continuing check Installation documentation

Register your app framework (only for Paid version)

The Speedchecker system needs to register your application identifier (with exception for free version), please communicate with our Speedchecker support team. You will need to know the Bundle Identifier of your application.

Initialization test

import SpeedcheckerSDK

class MySpeedTest: InternetSpeedTestDelegate {
    private var internetTest: InternetSpeedTest?
    private var locationManager = CLLocationManager() // for free version
    
    func init() {
        // paid version
        internetTest = InternetSpeedTest(licenseKey: "Your license key", delegate: self)

        // free version
        internetTest = InternetSpeedTest(delegate: self)
        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
            locationManager.requestAlwaysAuthorization()
        }
    }
}

Start test

    func start() {
        // paid version
        internetTest?.start() { error in
            if (error != .ok) { return print("speedTest did fail: \(error.rawValue)") }
        }
        // free version
        internetTest?.startFreeTest() { error in
            if (error != .ok) { return print("speedTest did fail: \(error.rawValue)") }
        }
    }

Stop test

    func stop() {
        internetTest?.forceFinish({ (error) in
            //
        })
    }

Delegate methods

    func internetTestError(error: SpeedTestError) {
        // Your code to handle the test finished by error
    }
    
    func internetTestFinish(result: SpeedTestResult) {
        // Your code to handle the test finished
        print(result.downloadSpeed.mbps)
        print(result.uploadSpeed.mbps)
        print(result.latencyInMs)
    }
    
    func internetTestReceived(servers: [SpeedTestServer]) {
        //
    }
    
    func internetTestSelected(server: SpeedTestServer, latency: Int, jitter: Int) {
        // Your code to handle latency result
    }
    
    func internetTestDownloadStart() {
        //
    }
    
    func internetTestDownloadFinish() {
        //
    }
    
    func internetTestDownload(progress: Double, speed: SpeedTestSpeed) {
        // Your code to handle result during the download test
    }
    
    func internetTestUploadStart() {
        //
    }
    
    func internetTestUploadFinish() {
        //
    }
    
    func internetTestUpload(progress: Double, speed: SpeedTestSpeed) {
        // Your code to handle result during the upload test
    }

Background Test integration instructions (only for Paid version)

Add required background modes to project

Enable Location updates and Background processing modes. You can enable them in Signing & Capabilities section in Xcode.

Screen Shot 2022-05-16 at 16 54 41

Or you can add keys directly to Info.plist.

<key>UIBackgroundModes</key>
<array>
	<string>location</string>
	<string>processing</string>
</array>

Add location usage descriptions to Info.plist

You should add next keys to Info.plist:

Screen Shot 2022-05-16 at 17 10 51

Or in source code:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>The app will run network tests in the background that may consume up to 100 MB from your mobile data plan. This anonymized data helps Internet providers to perform quality research and improve Internet infrastructure in your area.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>The app will run network tests in the background that may consume up to 100 MB from your mobile data plan. This anonymized data helps Internet providers to perform quality research and improve Internet infrastructure in your area.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to provide accurate speeds by using your nearest server.</string>

Add BGTaskSchedulerPermittedIdentifiers key to Info.plist

It is required to add this key with value com.speedchecker.bgtests to Info.plist for background processing to work.

Screen Shot 2022-05-16 at 17 19 39

Or in source code:

<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
	<string>com.speedchecker.bgtests</string>
</array>

Initialization code

Here is example of BackgroundTest setup in AppDelegate, which you could also find in our sample project.

import UIKit
import CoreLocation
import SpeedcheckerSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    var backgroundTest: BackgroundTest?
    var locationManager: CLLocationManager? = CLLocationManager()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Init BackgroundTest with your license key and optionally config URL
        if backgroundTest == nil {
            backgroundTest = BackgroundTest(licenseKey: "Your license key")
        }
        
        // Load your configuration
        backgroundTest?.loadConfig(launchOptions: launchOptions, completion: { success in
            // Handle case if configuration was not loaded successfully
        })
        
        // Setup location manager
        if launchOptions?[UIApplication.LaunchOptionsKey.location] != nil {
            locationManager = CLLocationManager()
        }
        locationManager?.delegate = self
        backgroundTest?.prepareLocationManager(locationManager: locationManager)
        
        // Register BGProcessingTask
        backgroundTest?.registerBGTask(locationManager)

        // Prompt the user for location permissions at this point, or wherever it best fits within the app's UI flow.
        
        return true
    }
}

extension AppDelegate: CLLocationManagerDelegate {
    
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        backgroundTest?.didChangeAuthorization(manager: manager, status: status)
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        backgroundTest?.didUpdateLocations(manager: manager, locations: locations)
    }
}

LaunchTest integration instructions (only for Paid version)

Initialization code

import UIKit
import SpeedcheckerSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var launchTest: LaunchTest?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Setup launch test
        launchTest = LaunchTest(licenseKey: "Your license key", url: "Your config URL")
        launchTest?.setup(launchOptions: launchOptions)
        return true
    }
}

iOS Documentation

InternetSpeedTest

This class provides speed test measurement between the device and a speed test server.

Functions, paid version

  • init(licenseKey: String? = nil, delegate: InternetSpeedTestDelegate)
  • start(_ completion: (SpeedTestError) -> Void)
  • start(_ servers: [SpeedTestServer], completion: (SpeedTestError) -> Void)
  • startWithOptions(_ options: SpeedTestOptions, _ completion: (SpeedTestError?) -> Void)
  • startWithOptions(_ options: SpeedTestOptions, servers: [SpeedTestServer], _ completion: (SpeedTestError?) -> Void)

Functions, free version

  • init(delegate: InternetSpeedTestDelegate?)
  • startFreeTest(_ completion: (SpeedTestError) -> Void)

Properties

  • msisdn: String? - MSISDN value used by SDK. Value is persisted and it is sufficient to pass it only once (e.g. after app install).
  • userID: String? - UserID value used by SDK. Value is persisted and it is sufficient to pass it only once (e.g. after app install).

InternetSpeedTestDelegate

This protocol provides results from the InternetSpeedTest class to your code.

Events

Speed test finished

  • internetTestError(error: SpeedTestError)
  • internetTestFinish(result: SpeedTestResult)

Speed test server connection established

  • internetTestReceived(servers: [SpeedTestServer])
  • internetTestSelected(server: SpeedTestServer, latency: Int, jitter: Int)

Speed test download

  • internetTestDownloadStart()
  • internetTestDownloadFinish()
  • internetTestDownload(progress: Double, speed: SpeedTestSpeed)

Speed test upload

  • internetTestUploadStart()
  • internetTestUploadFinish()
  • internetTestUpload(progress: Double, speed: SpeedTestSpeed)

SpeedTestError

This enum provides types of errors that occur during a speed test.

Cases

  • ok
  • invalidSettings
  • invalidServers
  • inProgress
  • failed
  • notSaved
  • cancelled
  • locationUndefined
  • appISPMismatch
  • invalidlicenseKey

SpeedTestResult

This object provides results once a speed test finished, typically used by the InternetSpeedTest class.

Properties

  • network: SpeedTestNetwork
  • server: SpeedTestServer
  • latencyType: SpeedTestLatencyType
  • latencyInMs: Int
  • jitter: Double
  • downloadSpeed: SpeedTestSpeed
  • uploadSpeed: SpeedTestSpeed
  • ipAddress: String?
  • ispName: String?
  • date: Date?
  • timeToFirstByteMs: Int
  • downloadTransferredMb: Double
  • uploadTransferredMb: Double
  • packetLoss: SCPacketLoss?
  • testID: String

SpeedTestServer

This object provides details about server used in speed test.

Properties

  • ID: Int?
  • type: SCServerType
  • scheme: String?
  • domain: String?
  • port: Int?
  • downloadFolderPath: String?
  • uploadFolderPath: String?
  • uploadScript: String?
  • countryCode: String?
  • country: String?
  • cityName: String?

SpeedTestSpeed

This object provides details of some data speed test type.

Properties

  • kbps: Double
  • mbps: Double
  • descriptionInKbps: String
  • descriptionInMbps: String

SpeedTestNetworkType

This enum provides network types, typically how a device was connected during the speed test.

Cases

  • any
  • wifi
  • cellular

SpeedTestOptions

This object provides details about speed test options used in speed test.

Properties

  • downloadTimeMs: Int - Download speed test duration in milliseconds.
  • uploadTimeMs: Int - Upload speed test duration in milliseconds.
  • downloadThreadsCount: Int? - Download threads count. If value is nil number of threads will be calculated based on active connection.
  • uploadThreadsCount: Int? - Upload threads count. If value is nil number of threads will be calculated based on active connection.
  • downloadSampleTimeMs: Int - Download test sampling time in milliseconds.
  • uploadSampleTimeMs: Int - Upload test sampling time in milliseconds.
  • additionalThreadsCount: Int - Max number of additional threads.
  • connectionTimeoutMs: Int - Connection timeout time in milliseconds.
  • sendResultsToSpeedChecker - Enable/disable sending speed test results to SpeedChecker servers.

BackgroundTest

This class provides background test measurements between the device and a test servers.

Functions

  • init(licenseKey: String? = nil, url: String? = nil, testsEnabled: Bool = true)
  • setBackgroundNetworkTesting(testsEnabled: Bool)
  • getBackgroundNetworkTestingEnabled() -> Bool
  • prepareLocationManager(locationManager: CLLocationManager?)
  • registerBGTask(_ locationManager: CLLocationManager?)
  • loadConfig(launchOptions: [UIApplication.LaunchOptionsKey: Any]?, completion: @escaping (Bool) -> Void)
  • didChangeAuthorization(manager: CLLocationManager, status: CLAuthorizationStatus)
  • didUpdateLocations(manager: CLLocationManager, locations: [CLLocation])

LaunchTest

Manages tests on app launch.

Functions

  • init(licenseKey: String? = nil, url: String? = nil, enabled: Bool = true, logsEnabled: Bool = false)
  • setup(launchOptions: [UIApplication.LaunchOptionsKey : Any]?)
  • setEnabled(_ enabled: Bool)
⚠️ **GitHub.com Fallback** ⚠️