From 55f6b51868461ec365e4b59f89dd86e8604bc500 Mon Sep 17 00:00:00 2001 From: manuroe <manuroe@users.noreply.github.com> Date: Thu, 1 Feb 2018 14:06:01 +0100 Subject: [PATCH] Make Device.swift usable from objc (#224) * 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 --- CHANGELOG.md | 3 +++ MatomoTracker/Device.swift | 41 ++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec0c327a..85a8d9b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/MatomoTracker/Device.swift b/MatomoTracker/Device.swift index 4dc2981b..9432b64b 100644 --- a/MatomoTracker/Device.swift +++ b/MatomoTracker/Device.swift @@ -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() @@ -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 { @@ -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" @@ -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)" @@ -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 }