DeviceGuru is a simple lib (Swift) to know the exact type of the device

Related tags

Utility DeviceGuru
Overview

DeviceGuru

DeviceGuru is a simple lib (Swift) to know the exact type of the device, e.g. iPhone 6 or iPhone 6s

  • Easy to use
  • Light weight

From version 5.0.0 it can also identify the simulator type, whether it's iPhone XR or iPhone 6

Installation

Using Swift Package Manager

Add to Package.swift:

.Package(url: "https://github.com/InderKumarRathore/DeviceGuru", branch: "master")
Using CocoaPods

Copy the pod dependency and add that to your pod file. e.g.

pod 'DeviceGuru'

then run the below command in terminal

pod install
Using Carthage

Specify DeviceGuru into your project's Cartfile:

github "InderKumarRathore/DeviceGuru"
Manually

Drag and drop this folder

Sources

files in your project

Usage

If you install from CocoaPods, you have to import the module. If you used drag and drop then there is no need of import

import DeviceGuru

In your code:

let deviceGuru = DeviceGuru()
let deviceName = deviceGuru.hardware()
let deviceCode = deviceGuru.hardwareString()
let platform = deviceGuru.platform()
print("\(deviceName) - \(deviceCode) - \(platform)") //Ex: iphone_7_PLUS - iPhone9,2 - iphone

Checkout Example Project!

Development

Want to contribute? Great! Just update the GeneratorDevice.plist

Then

cd Generator
./main.swift

The above command will auto generate the required code

Send the pull request 🚀

License

DeviceGuru is available under the MIT license. See the LICENSE file for more info.

Comments
  • Bump version for SPM to include iPhone 13

    Bump version for SPM to include iPhone 13

    I was using the 'iPhone13Family' branch because it had the iPhone 13 devices in it. That branch has now been removed, but SPM can only seem to find version 7.0.1 and not 7.0.3

    I believe 7.0.3 is the version that includes iPhone 13 devices.

    Hoping this is a quick fix. Thanks, Joe

    opened by pnome 6
  • Xcode 9 Beta Warnings

    Xcode 9 Beta Warnings

    Xcode compiler complains "Overlapping accesses to 'name', but modification requires exclusive access; consider copying to a local variable"

    DeviceGuru.swift file (lines 23 & 25). warnings

    1. sysctl(&name, 2, nil, &size, &name, 0)
    2. sysctl(&name, 2, &hw_machine, &size, &name, 0)
    opened by EverGod 6
  • Missing bundle version when using Carthage

    Missing bundle version when using Carthage

    Hi, I was trying to upload an app to AppStore Connect with DeviceGuru framework built using Carthage and I received this error:

    This bundle Payload/xxx.app/Frameworks/DeviceGuru.framework is invalid. The Info.plist file is missing the required key: CFBundleVersion.

    I checked Info.plist in the framework and version was actually missing. I checked also DeviceGuru project and it looks like bundle version is set to $(CURRENT_PROJECT_VERSION) but this option is empty in build settings.

    Can you fix this by adding some value to CURRENT_PROJECT_VERSION option in build setting, so I can successfully upload my app.

    Thanks

    opened by minixT 5
  • Project is not compiling - missing files

    Project is not compiling - missing files

    Hi,

    it looks like current master doesn't work. When I try to build the project I get this error:

    /.../DeviceGuru/Sources/DeviceGuru.swift:82:31: error: cannot find type 'Platform' in scope
        public func platform() -> Platform {
                                  ^~~~~~~~
    /.../DeviceGuru/Sources/DeviceGuru.swift:135:36: error: cannot find type 'DeviceVersion' in scope
        public func deviceVersion() -> DeviceVersion? {
                                       ^~~~~~~~~~~~~
    /.../DeviceGuru/Sources/DeviceGuru.swift:180:45: error: cannot find type 'DeviceVersion' in scope
        func getVersion(from string: String) -> DeviceVersion? {
                                                ^~~~~~~~~~~~~
    /.../DeviceGuru/Sources/DeviceGuru.swift:38:34: error: type 'Bundle' has no member 'module'
                if let path = Bundle.module.path(forResource: resource, ofType: type) {
                              ~~~~~~ ^~~~~~
    

    I found that Platform.swift and DeviceVersion.swift files are not added to the project.

    I'm using Xcode 12.1 and working on the code downloaded directly from the repository.

    Thanks

    opened by minixT 5
  • On a iPhone 7 with iOS 12.1, using Xcode 10.1 Beta 3, the method hard…

    On a iPhone 7 with iOS 12.1, using Xcode 10.1 Beta 3, the method hard…

    On a iPhone 7 with iOS 12.1, using Xcode 10.1 Beta 3, the method hardwareNumber returned nil instead of the phone version (9.2 in this case). Changing the method return type from Float to Double fixed the problem.

    opened by ricardopaiva 5
  • Missing example project

    Missing example project

    Normally, this type of projects would have an example app, as you can see here and here. I'll create an example and push a PR.

    What do you think? :smiley:

    Enhancement 
    opened by lfarah 5
  • Provide Objective-C examples?

    Provide Objective-C examples?

    I've been using DeviceUtil which is being replaced by DeviceGuru.

    Sadly, I'm not a Swift guru, so am hoping someone can provide examples on how to use DeviceGuru in my Objective-C project. Thanks.

    opened by cliffjoyce 4
  • Crash on DeviceGuru.init()

    Crash on DeviceGuru.init()

    Hello!

    Basically what's happening is when I'm debugging my application, sometimes this crash occurs. The most part happens when I put a break point in some line of code or try to stop on a break point.

    We also discovered that this crash happens on production code some times.

    We're testing on simulator (iPhone 11 Pro 14.4)

    The lib is up to date on 7.0.1 version, using cocoapods.

    Screen Shot 2021-04-06 at 10 00 05 Help Wanted 
    opened by bruno-hcr 4
  • Added a Package manifest for Swift 5.3 to resolve the Xcode 12 warning

    Added a Package manifest for Swift 5.3 to resolve the Xcode 12 warning

    Adding this library into Swift Package Manager using Xcode 12 generates a following warning "The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.0.99." There are a couple solutions to this that I know:

    1. Deployment target can be increased to .iOS(.v9) in the main Package.swift file.

    2. A separate Package manifest can be created to target a specific swift version.

    I went the second way to make changes smaller.

    opened by asolovev 4
  • The hardware string is swapped for the XS Max Global and XS Max China

    The hardware string is swapped for the XS Max Global and XS Max China

    According to multiple sources the iPhone11,4 belongs to the XS Max China and the iPhone11,6 belongs to the XS Max Global. I can also confirm that devices used in Germany are reporting iPhone11,6

    https://gist.github.com/adamawolf/3048717 https://www.theiphonewiki.com/wiki/Models

    Help Wanted 
    opened by gfoldv 4
  • iPhone10,3 being marked as `iPhone X China/Japan`

    iPhone10,3 being marked as `iPhone X China/Japan`

    This could be a bug, but probably more so a clarification question.

    I'm on 3.0.1 and running on my iPhone X I purchased through Verizon here in the United States. However the following device info is being printed:

    (lldb) po deviceGuru.hardwareString()
    "iPhone10,3"
    
    (lldb) po deviceGuru.hardwareDescription()
    ▿ Optional<String>
      - some : "iPhone X China/Japan"
    
    (lldb) po deviceGuru.hardware()
    DeviceGuru.Hardware.iphoneX_cn
    
    (lldb) po deviceGuru.hardwareNumber()
    10.3000002
    

    What's the difference between China/Japan and Global?

    opened by jeffscaturro-wf 4
  • Crash EXC_BREAKPOINT

    Crash EXC_BREAKPOINT

    Crashed: com.apple.main-thread
    0  DeviceGuru                     0xf6f4 $s10DeviceGuru36HardwareDetailProviderImplementationV14hardwareStringSSvgTf4d_n + 816
    1  DeviceGuru                     0x7894 $s10DeviceGuru0aB14ImplementationC15_hardwareString33_6D9CB63EE52D478D829B7739F6A9542CLLSSvg + 76
    2  DeviceGuru                     0x7a10 $s10DeviceGuru0aB14ImplementationC8platformAA8PlatformOvg + 16
    3  OurApp                        0x3bd620 SecureEnclaveService.hasSecureEnclave.getter + 14 (DeviceGuru+SecureEnclave.swift:14)
    

    how we invoke DeviceGuru in our code:

    extension DeviceGuru {
        func supportSecureEnclave() -> Bool {
            if platform == .iPodTouch { //line 14
                return false
            }
            ...    
       }
    

    We've got a lot of crashes with such stack trace for iOS 13 and iOS 14 users. DeviceGuru version is 10.0.1

    opened by jls21stuzo 4
  • M1 support

    M1 support

    Was looking in to how this might work. With the current implementation, running on an M1 mac appears to always yield iPad8,6. However sentry seems to be able to detect the difference with their implementation. I lack much time to work on this currently, but here is a start, in case that is useful.

    Generator/GeneratorDeviceList.plist
    	<key>iMac21,1</key>
    	<dict>
    		<key>name</key>
    		<string>iMac (24-inch, M1, 2021)</string>
    		<key>enum</key>
    		<string>IMAC_2021</string>
    	</dict>
    	<key>iMac21,2</key>
    	<dict>
    		<key>name</key>
    		<string>iMac (24-inch, M1, 2021)</string>
    		<key>enum</key>
    		<string>IMAC_2021</string>
    	</dict>
    	<key>Macmini9,1</key>
    	<dict>
    		<key>name</key>
    		<string>Mac mini (M1, 2020)</string>
    		<key>enum</key>
    		<string>MAC_MINI_2020</string>
    	</dict>
    	<key>MacBookAir10,1</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Air (M1, 2020)</string>
    		<key>enum</key>
    		<string>MACBOOK_AIR_2020</string>
    	</dict>
    	<key>Mac14,2</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Air (M2, 2022)</string>
    		<key>enum</key>
    		<string>MACBOOK_AIR_2022</string>
    	</dict>
    	<key>MacBookPro17,1</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (13-inch, M1, 2020)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_2020</string>
    	</dict>
    	<key>MacBookPro18,1</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (16-inch, 2021)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_16_2021</string>
    	</dict>
    	<key>MacBookPro18,2</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (16-inch, 2021)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_16_2021</string>
    	</dict>
    	<key>MacBookPro18,3</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (14-inch, 2021)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_14_2021</string>
    	</dict>
    	<key>MacBookPro18,4</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (14-inch, 2021)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_14_2021</string>
    	</dict>
    	<key>Mac14,7</key>
    	<dict>
    		<key>name</key>
    		<string>MacBook Pro (13-inch, M2, 2022)</string>
    		<key>enum</key>
    		<string>MACBOOK_PRO_2022</string>
    	</dict>
    
    Generator/main.swift
    diff --git a/Generator/main.swift b/Generator/main.swift
    index 09c145b..87d7449 100755
    --- a/Generator/main.swift
    +++ b/Generator/main.swift
    @@ -98,6 +98,8 @@ func main() {
         let unknownIpadCase = "unknownIpad"
         let unknownAppleWatchCase = "unknownAppleWatch"
         let unknownAppleTVCase = "unknownAppleTV"
    +    let unknownImacCase = "unknownImac"
    +    let unknownMacCase = "unknownMac"
     
     
         var deviceList: [String: [String: AnyObject]] = [:]
    @@ -128,7 +130,9 @@ func main() {
             + "\n\(tabSpacing)case \(unknownIpodCase)"
             + "\n\(tabSpacing)case \(unknownIpadCase)"
             + "\n\(tabSpacing)case \(unknownAppleWatchCase)"
    -        + "\n\(tabSpacing)case \(unknownAppleTVCase)\n"
    +        + "\n\(tabSpacing)case \(unknownAppleTVCase)"
    +        + "\n\(tabSpacing)case \(unknownImacCase)"
    +        + "\n\(tabSpacing)case \(unknownMacCase)\n"
     
             + "\n\(tabSpacing)case simulator\n"
     
    @@ -166,6 +170,20 @@ func main() {
             let swiftEnumCase = normalizedEnum($0.enumCase)
             enumString += "\n\(tabSpacing)case \(swiftEnumCase)"
         }
    +    enumString += "\n"
    +
    +    let iMacModels = getUniqueSortedModels(havingPrefix: "iMac", from: generatorDeviceList)
    +    iMacModels.forEach {
    +        let swiftEnumCase = normalizedEnum($0.enumCase)
    +        enumString += "\n\(tabSpacing)case \(swiftEnumCase)"
    +    }
    +    enumString += "\n"
    +
    +    let macModels = getUniqueSortedModels(havingPrefix: "Mac", from: generatorDeviceList)
    +    macModels.forEach {
    +        let swiftEnumCase = normalizedEnum($0.enumCase)
    +        enumString += "\n\(tabSpacing)case \(swiftEnumCase)"
    +    }
     
         print("Creating \(enumFile)")
         do {
    @@ -206,7 +224,9 @@ func main() {
                 + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"iPod\")) { return .\(unknownIpodCase) }\n"
                 + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"iPad\")) { return .\(unknownIpadCase) }\n"
                 + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"Watch\")) { return .\(unknownAppleWatchCase) }\n"
    -            + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"AppleTV\")) { return .\(unknownAppleTVCase) }\n\n"
    +            + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"AppleTV\")) { return .\(unknownAppleTVCase) }\n"
    +            + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"iMac\")) { return .\(unknownImacCase) }\n"
    +            + "\(tabSpacing)\(tabSpacing)if (hardwareString.hasPrefix(\"Mac\")) { return .\(unknownMacCase) }\n\n"
                 + "\(tabSpacing)\(tabSpacing)return .unknownDevice\n"
                 + "\(tabSpacing)}\n"
                 + "}\n"
    
    opened by alpha0010 0
  • [Performance] Split the plist into platform specific to gain some performance

    [Performance] Split the plist into platform specific to gain some performance

    Right now (Oct 2022) the size of the file is 19.2 KB which is not that significant, but eventually it will grow. I think we should start thinking to split this plist based on multiple platforms. It might not be a huge improvement to iPhone/iPad but can be significant to watch OS

    Although we already made improvement by loading the plist file only first time and subsequent information is read from user defaults which is quite cheap. Let's gather some data and then take the decision.

    Enhancement Help Wanted 
    opened by InderKumarRathore 0
Owner
Inder Kumar
Follow me on twitter : https://twitter.com/ikr_303
Inder Kumar
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️

Welcome to Codextended — a suite of extensions that aims to make Swift’s Codable API easier to use by giving it type inference-powered capabilities an

John Sundell 1.4k Jan 2, 2023
Swift type modelling the success/failure of arbitrary operations.

Result This is a Swift µframework providing Result<Value, Error>. Result<Value, Error> values are either successful (wrapping Value) or failed (wrappi

Antitypical 2.5k Dec 26, 2022
Type-Safe Associated Objects in Swift

Type-Safe Associated Objects in Swift TSAO is an implementation of type-safe associated objects in Swift. Objective-C associated objects are useful, b

Lily Ballard 135 Dec 21, 2022
UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift.

UTIKit UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift. Features UTIKit is a full featured library including entire UTI functions. Conver

Hiroki Kato 254 Nov 27, 2022
Swift package for accessing SF Symbols in a type safe manner.

Swift Package Information Code Coverage Swift package for accessing SF Symbols in a type safe manner. Features ?? Contains all SF Symbols - 1.0, 2.0,

null 6 Dec 7, 2021
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Mathias Quintero 9 Sep 25, 2022
🚀Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

??Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

Cheng Zhang 18 Mar 9, 2022
MediaType is a library that can be used to create Media Types in a type-safe manner.

This is a general purpose Swift library for a concept of typed treatment for Media Types. We use this library on clients and servers to speak the same dialect and to enjoy all the comfort strong types provide over raw strings.

21Gram Consulting 79 Jul 19, 2022
A Codable Undefinable type for handling JSON undefined values.

Undefinable Overview The purpose of this type is represent the JSON undefined state in Swift structs and classes. The Undefinable enum is a generic wi

David Monagle 3 Dec 18, 2022
A CMIO Camera Extension of the creative camera type, with configuration app

ArtFilm A CMIO Camera Extension of the creative camera type, with configuration app ArtFilm is the sample code for the blog post Getting To Grips With

Halle 7 Jan 1, 2023
A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

Brent Mifsud 33 Oct 3, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
RandomKit is a Swift framework that makes random data generation simple and easy.

RandomKit is a Swift framework that makes random data generation simple and easy. Build Status Installation Compatibility Swift Package Manager CocoaP

Nikolai Vazquez 1.5k Dec 29, 2022
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

Viktor G 26 Dec 14, 2022
A simple Swift package for counting the Syllables in a sentence.

A simple Swift package for counting the Syllables in a sentence.

null 2 Jan 3, 2022
A simple Swift utility for producing pseudolocalized strings.

Build your App UI to adapt and respond to translations, and find localization bugs!

Reece Como 2 Sep 28, 2021
AnalyticsKit for Swift is designed to combine various analytical services into one simple tool.

?? AnalyticsKit AnalyticsKit for Swift is designed to combine various analytical services into one simple tool. To send information about a custom eve

Broniboy 6 Jan 14, 2022
Angle is a simple Swift library that provides Angle structure representing angles.

Angle is a simple Swift library that provides Angle structure representing angles. It handles angles using circular measure by default but is al

Geonu Jeon 2 Nov 30, 2021
A simple solution for tiring [weak self] in swift

Weakifiable A simple solution for tiring [weak self] in swift Usage give this repo a Star ⭐️ Add EBWeakifiable to your Project. simply after each clos

Emad Beyrami 4 Nov 6, 2021