API documentation - speedchecker/speedchecker-sdk-ios GitHub Wiki
Before continuing check Installation documentation
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.
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()
}
}
}
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)") }
}
}
func stop() {
internetTest?.forceFinish({ (error) in
//
})
}
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
}
Enable Location updates
and Background processing
modes. You can enable them in Signing & Capabilities section in Xcode.

Or you can add keys directly to Info.plist
.
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>processing</string>
</array>
You should add next keys to Info.plist
:

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>
It is required to add this key with value com.speedchecker.bgtests
to Info.plist
for background processing to work.

Or in source code:
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.speedchecker.bgtests</string>
</array>
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)
}
}
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
}
}
This class provides speed test measurement between the device and a speed test server.
- 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)
- init(delegate: InternetSpeedTestDelegate?)
- startFreeTest(_ completion: (SpeedTestError) -> Void)
- 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).
This protocol provides results from the InternetSpeedTest class to your code.
- internetTestError(error: SpeedTestError)
- internetTestFinish(result: SpeedTestResult)
- internetTestReceived(servers: [SpeedTestServer])
- internetTestSelected(server: SpeedTestServer, latency: Int, jitter: Int)
- internetTestDownloadStart()
- internetTestDownloadFinish()
- internetTestDownload(progress: Double, speed: SpeedTestSpeed)
- internetTestUploadStart()
- internetTestUploadFinish()
- internetTestUpload(progress: Double, speed: SpeedTestSpeed)
This enum provides types of errors that occur during a speed test.
- ok
- invalidSettings
- invalidServers
- inProgress
- failed
- notSaved
- cancelled
- locationUndefined
- appISPMismatch
- invalidlicenseKey
This object provides results once a speed test finished, typically used by the InternetSpeedTest class.
- 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
This object provides details about server used in speed test.
- ID: Int?
- type: SCServerType
- scheme: String?
- domain: String?
- port: Int?
- downloadFolderPath: String?
- uploadFolderPath: String?
- uploadScript: String?
- countryCode: String?
- country: String?
- cityName: String?
This object provides details of some data speed test type.
- kbps: Double
- mbps: Double
- descriptionInKbps: String
- descriptionInMbps: String
This enum provides network types, typically how a device was connected during the speed test.
- any
- wifi
- cellular
This object provides details about speed test options used in speed test.
-
downloadTimeMs: Int
- Download speed test duration in milliseconds. -
uploadTimeMs: Int
- Upload speed test duration in milliseconds. -
downloadThreadsCount: Int?
- Download threads count. If value isnil
number of threads will be calculated based on active connection. -
uploadThreadsCount: Int?
- Upload threads count. If value isnil
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.
This class provides background test measurements between the device and a test servers.
- 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])
Manages tests on app launch.
- init(licenseKey: String? = nil, url: String? = nil, enabled: Bool = true, logsEnabled: Bool = false)
- setup(launchOptions: [UIApplication.LaunchOptionsKey : Any]?)
- setEnabled(_ enabled: Bool)