Skip to content

Commit

Permalink
Make Device.swift usable from objc (#224)
Browse files Browse the repository at this point in the history
* Device.swift: make it a class usable from objc

* Device.swift: Add human readable platform names for iPhone 8, 8 Plus and X

* Device.swift: Make nativeScreenSize return CGSize.zero if the value is not defined on the running platform
  • Loading branch information
manuroe authored and brototyp committed Feb 1, 2018
1 parent 7a273a1 commit 55f6b51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
* Device.swift is now usable from Objective-C and recognizes iPhone 8 and X platform identifier. [#224](https://github.com/matomo-org/matomo-sdk-ios/pull/224) (by @manuroe)

## 5.0.0-beta1
* **feature** It now is possible to use multiple PiwikTracker instances within one appliaction. Please check [this](https://github.com/matomo-org/matomo-sdk-ios/wiki/Migration#50) guide how to migrate from the shared instance in version 4. [#164](https://github.com/piwik/piwik-sdk-ios/pull/164)
* **feature** Added compatibility to custom variables. [#223](https://github.com/matomo-org/matomo-sdk-ios/pull/223) (by @manuroe and @zantoku)
Expand Down
41 changes: 30 additions & 11 deletions MatomoTracker/Device.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
public struct Device {
import Foundation

final public class Device: NSObject {
/// Creates an returns a new device object representing the current device
public static func makeCurrentDevice() -> Device {
@objc public static func makeCurrentDevice() -> Device {
let platform = currentPlatform()
let humanReadablePlatformName = humanReadablePlatformNameForCurrentDevice()
let os = osVersionForCurrentDevice()
Expand All @@ -14,20 +16,31 @@ public struct Device {
}

/// The platform name of the device i.e. "iPhone1,1" or "iPad3,6"
public let platform: String
@objc public let platform: String

/// A human readable version of the platform name i.e. "iPhone 6 Plus" or "iPad Air 2 (WiFi)"
/// Will be nil if no human readable string was found.
public let humanReadablePlatformName: String?
@objc public let humanReadablePlatformName: String?

/// The version number of the OS as String i.e. "1.2" or "9.4"
public let osVersion: String
@objc public let osVersion: String

// The screen size
public let screenSize: CGSize
/// The screen size
@objc public let screenSize: CGSize

// The native screen size
public let nativeScreenSize: CGSize?
/// The native screen size
/// Will be CGSize.zero if the value is not defined on the running platorm.
@objc public let nativeScreenSize: CGSize

required public init(platform: String, humanReadablePlatformName: String? = nil, osVersion: String, screenSize: CGSize, nativeScreenSize: CGSize? = nil) {
self.platform = platform
self.humanReadablePlatformName = humanReadablePlatformName
self.osVersion = osVersion
self.screenSize = screenSize
self.nativeScreenSize = nativeScreenSize != nil ? nativeScreenSize! : CGSize.zero

super.init()
}
}

extension Device {
Expand Down Expand Up @@ -69,6 +82,12 @@ extension Device {
case "iPhone9,2": return "iPhone 7 Plus (GSM+CDMA)"
case "iPhone9,3": return "iPhone 7 (Global)"
case "iPhone9,4": return "iPhone 7 Plus (Global)"
case "iPhone10,1": return "iPhone 8 (GSM+CDMA)"
case "iPhone10,2": return "iPhone 8 Plus (GSM+CDMA)"
case "iPhone10,3": return "iPhone X (GSM+CDMA)"
case "iPhone10,4": return "iPhone 8 (Global)"
case "iPhone10,5": return "iPhone 8 Plus (Global)"
case "iPhone10,6": return "iPhone X (Global)"

// iPod
case "iPod1,1": return "iPod Touch 1G"
Expand Down Expand Up @@ -136,7 +155,7 @@ extension Device {
#if os(OSX)
import AppKit
extension Device {
/// Reaturns the version number of the current OS as String i.e. "1.2" or "9.4"
/// Returns the version number of the current OS as String i.e. "1.2" or "9.4"
internal static func osVersionForCurrentDevice() -> String {
let version = ProcessInfo.processInfo.operatingSystemVersion
return "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
Expand All @@ -157,7 +176,7 @@ extension Device {
import UIKit
extension Device {

/// Reaturns the version number of the current OS as String i.e. "1.2" or "9.4"
/// Returns the version number of the current OS as String i.e. "1.2" or "9.4"
internal static func osVersionForCurrentDevice() -> String {
return UIDevice.current.systemVersion
}
Expand Down

0 comments on commit 55f6b51

Please sign in to comment.