Skip to content

Commit

Permalink
Merge pull request #2 from iSapozhnik/feature/adding-new-devices
Browse files Browse the repository at this point in the history
Feature/adding new devices
  • Loading branch information
iSapozhnik authored Oct 31, 2018
2 parents b341f4a + f4c2fd5 commit c9f4e91
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Haptico.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Haptico'
s.version = '1.0.1'
s.version = '1.0.2'
s.summary = 'Haptico - easy to use haptic feedback generator with pattern-play support'

# This description is used to generate tags and improve search results.
Expand Down
94 changes: 64 additions & 30 deletions Haptico/Classes/Extensions/UIDevice+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

// https://github.com/schickling/Device.swift/blob/master/Device/UIDeviceExtension.swift
// https://ipsw.me/otas
// MARK: -
internal extension UIDevice {

Expand All @@ -21,21 +22,24 @@ internal extension UIDevice {
return deviceType == .iPhone6S || deviceType == .iPhone6SPlus ||
deviceType == .iPhone7 || deviceType == .iPhone7Plus ||
deviceType == .iPhone8 || deviceType == .iPhone8Plus ||
deviceType == .iPhoneX
deviceType == .iPhoneX || deviceType == .iPhoneXR ||
deviceType == .iPhoneXS || deviceType == .iPhoneXSMax

}
}

internal var hasHapticFeedback: Bool {
get {
return deviceType == .iPhone7 || deviceType == .iPhone7Plus ||
deviceType == .iPhone8 || deviceType == .iPhone8Plus ||
deviceType == .iPhoneX
deviceType == .iPhone8 || deviceType == .iPhone8Plus ||
deviceType == .iPhoneX || deviceType == .iPhoneXR ||
deviceType == .iPhoneXS || deviceType == .iPhoneXSMax
}
}
}

/// Enum representing the different types of iOS devices available
internal enum DeviceType: String, EnumProtocol {
internal enum DeviceType: String {
case iPhone2G

case iPhone3G
Expand Down Expand Up @@ -63,6 +67,9 @@ internal enum DeviceType: String, EnumProtocol {
case iPhone8Plus

case iPhoneX
case iPhoneXS
case iPhoneXSMax
case iPhoneXR

case iPodTouch1G
case iPodTouch2G
Expand Down Expand Up @@ -113,7 +120,6 @@ internal enum DeviceType: String, EnumProtocol {
// MARK: Variables
/// Returns the display name of the device type
internal var displayName: String {

switch self {
case .iPhone2G: return "iPhone 2G"
case .iPhone3G: return "iPhone 3G"
Expand All @@ -133,6 +139,9 @@ internal enum DeviceType: String, EnumProtocol {
case .iPhone8: return "iPhone 8"
case .iPhone8Plus: return "iPhone 8 Plus"
case .iPhoneX: return "iPhone X"
case .iPhoneXS: return "iPHone XS"
case .iPhoneXSMax: return "iPhone XS Max"
case .iPhoneXR: return "iPhone XR"
case .iPodTouch1G: return "iPod Touch 1G"
case .iPodTouch2G: return "iPod Touch 2G"
case .iPodTouch3G: return "iPod Touch 3G"
Expand Down Expand Up @@ -181,7 +190,10 @@ internal enum DeviceType: String, EnumProtocol {
case .iPhone8: return ["iPhone10,1", "iPhone10,4"]
case .iPhone8Plus: return ["iPhone10,2", "iPhone10,5"]
case .iPhoneX: return ["iPhone10,3", "iPhone10,6"]

case .iPhoneXS: return ["iPhone11,2"]
case .iPhoneXSMax: return ["iPhone11,4", "iPhone11,6"]
case .iPhoneXR: return ["iPhone11,8"]

case .iPodTouch1G: return ["iPod1,1"]
case .iPodTouch2G: return ["iPod2,1"]
case .iPodTouch3G: return ["iPod3,1"]
Expand Down Expand Up @@ -224,29 +236,51 @@ internal enum DeviceType: String, EnumProtocol {
}
}


// MARK: - EnumProtocol
internal protocol EnumProtocol: Hashable {
/// -returns: All Enum Values
static var all: [Self] { get }
}

// MARK: -
// MARK: - Extensions
internal extension EnumProtocol {

static var all: [Self] {
typealias Type = Self
let cases = AnySequence { () -> AnyIterator<Type> in
var raw = 0
return AnyIterator {
let current: Self = withUnsafePointer(to: &raw) { $0.withMemoryRebound(to: Type.self, capacity: 1) { $0.pointee } }
guard current.hashValue == raw else { return nil }
raw += 1
return current
}
}

return Array(cases)
extension DeviceType {
static var all: [DeviceType] {
return [
iPhone2G,
iPhone3G,
iPhone3GS,
iPhone4,
iPhone4S,
iPhone5,
iPhone5C,
iPhone5S,
iPhone6,
iPhone6Plus,
iPhone6S,
iPhone6SPlus,
iPhoneSE,
iPhone7,
iPhone7Plus,
iPhone8,
iPhone8Plus,
iPhoneX,
iPhoneXS,
iPhoneXSMax,
iPhoneXR,
iPodTouch1G,
iPodTouch2G,
iPodTouch3G,
iPodTouch4G,
iPodTouch5G,
iPodTouch6G,
iPad,
iPad2,
iPad3,
iPad4,
iPadMini,
iPadMiniRetina,
iPadMini3,
iPadMini4,
iPadAir,
iPadAir2,
iPadPro9Inch,
iPadPro10p5Inch,
iPadPro12Inch,
simulator,
notAvailable
]
}
}

0 comments on commit c9f4e91

Please sign in to comment.