Skip to content

Commit e852258

Browse files
Add Target and support for tvOS
1 parent edd01e3 commit e852258

13 files changed

Lines changed: 442 additions & 22 deletions

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ language: swift
22
script:
33
- set -o pipefail
44
- swift --version
5-
- xcodebuild clean build test -project DeviceIdentificator.xcodeproj -scheme DeviceIdentificator -destination "platform=iOS Simulator,name=iPhone 7" | xcpretty -f `xcpretty-travis-formatter`
6-
- bash <(curl -s https://codecov.io/bash) -cF ios -J 'DeviceIdentificator'
5+
- xcodebuild clean build test -project DeviceIdentificator.xcodeproj -scheme DeviceIdentificator-iOS -destination "platform=iOS Simulator,name=iPhone 7" | xcpretty -f `xcpretty-travis-formatter`
6+
- bash <(curl -s https://codecov.io/bash) -cF iPhone -J 'DeviceIdentificator'
7+
- xcodebuild clean build test -project DeviceIdentificator.xcodeproj -scheme DeviceIdentificator-iOS -destination "platform=iOS Simulator,name=iPad Air 2" | xcpretty -f `xcpretty-travis-formatter`
8+
- bash <(curl -s https://codecov.io/bash) -cF iPad -J 'DeviceIdentificator'
9+
- xcodebuild clean build test -project DeviceIdentificator.xcodeproj -scheme DeviceIdentificator-tvOS -destination "platform=tvOS Simulator,name=Apple TV" | xcpretty -f `xcpretty-travis-formatter`
10+
- bash <(curl -s https://codecov.io/bash) -cF tvOS -J 'DeviceIdentificator'
711
- swiftlint lint
812
- pod lib lint

DeviceIdentificator.xcodeproj/project.pbxproj

Lines changed: 246 additions & 4 deletions
Large diffs are not rendered by default.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0940"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "E20BA6192139DD42005BA13B"
18+
BuildableName = "DeviceIdentificator.framework"
19+
BlueprintName = "DeviceIdentificator-tvOS"
20+
ReferencedContainer = "container:DeviceIdentificator.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
codeCoverageEnabled = "YES"
30+
shouldUseLaunchSchemeArgsEnv = "YES">
31+
<Testables>
32+
<TestableReference
33+
skipped = "NO">
34+
<BuildableReference
35+
BuildableIdentifier = "primary"
36+
BlueprintIdentifier = "E20BA6252139DD8D005BA13B"
37+
BuildableName = "DeviceIdentificator-tvOSTests.xctest"
38+
BlueprintName = "DeviceIdentificator-tvOSTests"
39+
ReferencedContainer = "container:DeviceIdentificator.xcodeproj">
40+
</BuildableReference>
41+
</TestableReference>
42+
</Testables>
43+
<MacroExpansion>
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "E20BA6192139DD42005BA13B"
47+
BuildableName = "DeviceIdentificator.framework"
48+
BlueprintName = "DeviceIdentificator-tvOS"
49+
ReferencedContainer = "container:DeviceIdentificator.xcodeproj">
50+
</BuildableReference>
51+
</MacroExpansion>
52+
<AdditionalOptions>
53+
</AdditionalOptions>
54+
</TestAction>
55+
<LaunchAction
56+
buildConfiguration = "Debug"
57+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
58+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
launchStyle = "0"
60+
useCustomWorkingDirectory = "NO"
61+
ignoresPersistentStateOnLaunch = "NO"
62+
debugDocumentVersioning = "YES"
63+
debugServiceExtension = "internal"
64+
allowLocationSimulation = "YES">
65+
<MacroExpansion>
66+
<BuildableReference
67+
BuildableIdentifier = "primary"
68+
BlueprintIdentifier = "E20BA6192139DD42005BA13B"
69+
BuildableName = "DeviceIdentificator.framework"
70+
BlueprintName = "DeviceIdentificator-tvOS"
71+
ReferencedContainer = "container:DeviceIdentificator.xcodeproj">
72+
</BuildableReference>
73+
</MacroExpansion>
74+
<AdditionalOptions>
75+
</AdditionalOptions>
76+
</LaunchAction>
77+
<ProfileAction
78+
buildConfiguration = "Release"
79+
shouldUseLaunchSchemeArgsEnv = "YES"
80+
savedToolIdentifier = ""
81+
useCustomWorkingDirectory = "NO"
82+
debugDocumentVersioning = "YES">
83+
<MacroExpansion>
84+
<BuildableReference
85+
BuildableIdentifier = "primary"
86+
BlueprintIdentifier = "E20BA6192139DD42005BA13B"
87+
BuildableName = "DeviceIdentificator.framework"
88+
BlueprintName = "DeviceIdentificator-tvOS"
89+
ReferencedContainer = "container:DeviceIdentificator.xcodeproj">
90+
</BuildableReference>
91+
</MacroExpansion>
92+
</ProfileAction>
93+
<AnalyzeAction
94+
buildConfiguration = "Debug">
95+
</AnalyzeAction>
96+
<ArchiveAction
97+
buildConfiguration = "Release"
98+
revealArchiveInOrganizer = "YES">
99+
</ArchiveAction>
100+
</Scheme>

Source/DeviceIdentificator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright © 2018 Sebastián Varela. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
#import <Foundation/Foundation.h>
1010

1111
//! Project version number for DeviceIdentificator.
1212
FOUNDATION_EXPORT double DeviceIdentificatorVersionNumber;

Source/DeviceIdentifier.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ internal struct DeviceIdentifier {
6161
case "iPad6,11", "iPad6,12": return .iPad5G
6262
case "iPad7,5", "iPad7,6": return .iPad6G
6363

64+
case "AppleTV5,3": return .appleTV4G
65+
case "AppleTV6,2": return .appleTV4K
66+
6467
default: return nil
6568
}
6669
}

Source/DeviceModel+Helpers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
3+
public extension DeviceModel {
4+
public var isSimulator: Bool {
5+
switch self {
6+
case .iPadSimulator, .iPhoneSimulator, .appleTVSimulator:
7+
return true
8+
default:
9+
return false
10+
}
11+
}
12+
13+
public var isAppleTV: Bool {
14+
return name.hasPrefix("Apple TV")
15+
}
16+
17+
public var isIpad: Bool {
18+
return name.hasPrefix("iPad")
19+
}
20+
21+
public var isIphone: Bool {
22+
return name.hasPrefix("iPhone")
23+
}
24+
}

Source/DeviceModel+IsSimulator.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

Source/DeviceModel+Name.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ public extension DeviceModel {
4848
case .iPad5G: return "iPad 5G"
4949
case .iPad6G: return "iPad 6G"
5050

51+
case .appleTV4G: return "Apple TV 4G"
52+
case .appleTV4K: return "Apple TV 4K"
53+
5154
case .iPadSimulator: return "iPad Simulator"
5255
case .iPhoneSimulator: return "iPhone Simulator"
56+
case .appleTVSimulator: return "Apple TV Simulator"
5357

5458
case .iPhoneUnknown(let model): return "Unknown iPhone (\(model))"
5559
case .iPadUnknown(let model): return "Unknown iPad (\(model))"

Source/DeviceModel.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import UIKit
23

34
public enum DeviceModel: Equatable {
45
case iPhone1G
@@ -46,8 +47,12 @@ public enum DeviceModel: Equatable {
4647
case iPad5G
4748
case iPad6G
4849

50+
case appleTV4G
51+
case appleTV4K
52+
4953
case iPadSimulator
5054
case iPhoneSimulator
55+
case appleTVSimulator
5156

5257
case iPhoneUnknown(model: String)
5358
case iPadUnknown(model: String)
@@ -57,8 +62,12 @@ public enum DeviceModel: Equatable {
5762
internal init(_ identifier: DeviceIdentifier) {
5863
guard let model = identifier.model else {
5964
if identifier.rawValue == "i386" || identifier.rawValue == "x86_64" {
60-
let smallerScreen = UIScreen.main.bounds.size.width < 768
61-
self = smallerScreen ? .iPhoneSimulator : .iPadSimulator
65+
#if os(iOS)
66+
let smallerScreen = UIScreen.main.bounds.size.width < 768
67+
self = smallerScreen ? .iPhoneSimulator : .iPadSimulator
68+
#elseif os(tvOS)
69+
self = .appleTVSimulator
70+
#endif
6271
} else if identifier.rawValue.hasPrefix("iPhone") {
6372
self = .iPhoneUnknown(model: identifier.rawValue)
6473
} else if identifier.rawValue.hasPrefix("iPod") {

Source/UIDeviceExtensions.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public extension UIDevice {
3232

3333
@objc
3434
public var isIpad: Bool {
35-
return deviceModel.name.contains("iPad")
35+
return deviceModel.isIpad
36+
}
37+
38+
@objc
39+
public var isIphone: Bool {
40+
return deviceModel.isIphone
41+
}
42+
43+
@objc
44+
public var isAppleTV: Bool {
45+
return deviceModel.isAppleTV
3646
}
3747
}

0 commit comments

Comments
 (0)