Super-lightweight library to detect used device

Overview

Device.swift

Language License Platform Documentation Pod Version Carthage Compatible

Super-lightweight library to detect used device

Device.swift extends the UIDevice class by adding a property:

var deviceType: DeviceType

Install

Carthage

Add the following to your Cartfile and follow these instructions

github "schickling/Device.swift"

CocoaPods

To integrate Device into your project add the following to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'Device.swift'

Usage

import Device

// Use import Device_swift if you're using Cocoapods

let deviceType = UIDevice.current.deviceType

switch deviceType {
  case .iPhone6SPlus: print("Do stuff for iPhone6S Plus")
  case .iPadMini: print("Do stuff for iPad mini")
  default: print("Check other available cases of DeviceType")
}

How to make release

  • Update pod version in podspec
  • Add tag
  • Add validate pod pod trunk push Device.swift.podspec --allow-warnings
  • Push to CocoaPods
  • Create release in github for with attached file for carthage
carthage build --no-skip-current
carthage archive Device

Also, check out our Documentation

Comments
  • BAD_ACCESS for CaseIterable .allCases

    BAD_ACCESS for CaseIterable .allCases

    I think this is related to issue #38 but after updating to 1.1.1 I still get a crash.

    Same cause, when accessing deviceType.

    We're trying to use Xcode 9.3 and Carthage 0.27.0

    After pulling upstream in to duckduckgo/iOS I updated Carthage to point at 1.1.1 and cleared my Carthage cache under ~/Library and the built binaries it creates relative to the project.

    I've attached a sample project that demonstrates the problem. Run the app and tap "CRASH ME". It simply calls an action which tries to print the current device type to the console:

    print(UIDevice.current.deviceType)

    Thread 1 Queue : com.apple.main-thread (serial)
    #0	0x000000010b22388f in DeviceType.hashValue.getter ()
    #1	0x000000010b223ebf in protocol witness for Hashable.hashValue.getter in conformance DeviceType [inlined] ()
    #2	0x000000010b223eb6 in specialized closure #1 in closure #1 in static CaseIterable<>.allCases.getter at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:235
    #3	0x000000010b2263b1 in specialized closure #1 in closure #1 in static CaseIterable<>.allCases.getter [inlined] ()
    #4	0x000000010b2263a9 in partial apply for specialized  ()
    #5	0x000000010e4427b5 in _ClosureBasedIterator.next() ()
    #6	0x000000010e442801 in protocol witness for IteratorProtocol.next() in conformance _ClosureBasedIterator<A> ()
    #7	0x000000010e44296d in _IteratorBox.next() ()
    #8	0x000000010b2242ae in specialized AnyIterator.next() [inlined] ()
    #9	0x000000010b224296 in specialized protocol witness for IteratorProtocol.next() in conformance AnyIterator<A> [inlined] ()
    #10	0x000000010b224296 in specialized _copySequenceToContiguousArray<A>(_:) ()
    #11	0x000000010b225811 in specialized Sequence._copyToContiguousArray() [inlined] ()
    #12	0x000000010b225803 in specialized protocol witness for Sequence._copyToContiguousArray() in conformance _ClosureBasedSequence<A> [inlined] ()
    #13	0x000000010b225803 in specialized _SequenceBox.__copyToContiguousArray() [inlined] ()
    #14	0x000000010b225803 in specialized AnySequence._copyToContiguousArray() [inlined] ()
    #15	0x000000010b225803 in specialized protocol witness for Sequence._copyToContiguousArray() in conformance AnySequence<A> [inlined] ()
    #16	0x000000010b225803 in specialized Array.init<A>(_:) [inlined] ()
    #17	0x000000010b225803 in specialized static CaseIterable<>.allCases.getter [inlined] at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:231
    #18	0x000000010b225803 in specialized DeviceType.init(identifier:) [inlined] at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:197
    #19	0x000000010b225803 in DeviceType.init(identifier:) [inlined] at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:195
    #20	0x000000010b225803 in specialized static DeviceType.current.getter at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:90
    #21	0x000000010b223e80 in static DeviceType.current.getter [inlined] ()
    #22	0x000000010b223e7b in UIDevice.deviceType.getter at /Users/brindy/Projects/Personal/CrashSample/Carthage/Checkouts/Device.swift/Device/UIDeviceExtension.swift:215
    #23	0x000000010af3aad5 in ViewController.crashMe() at /Users/brindy/Projects/Personal/CrashSample/CrashSample/ViewController.swift:26
    #24	0x000000010af3ab74 in @objc ViewController.crashMe() ()
    #25	0x000000010c102448 in -[UIApplication sendAction:to:from:forEvent:] ()
    #26	0x000000010c27d804 in -[UIControl sendAction:to:forEvent:] ()
    #27	0x000000010c27db21 in -[UIControl _sendActionsForEvents:withEvent:] ()
    #28	0x000000010c27ca69 in -[UIControl touchesEnded:withEvent:] ()
    #29	0x000000010c17711f in -[UIWindow _sendTouchesForEvent:] ()
    #30	0x000000010c178821 in -[UIWindow sendEvent:] ()
    #31	0x000000010c11c370 in -[UIApplication sendEvent:] ()
    #32	0x000000010ca5d57f in __dispatchPreprocessedEventFromEventQueue ()
    #33	0x000000010ca60194 in __handleEventQueueInternal ()
    #34	0x000000010ed44bb1 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
    #35	0x000000010ed294af in __CFRunLoopDoSources0 ()
    #36	0x000000010ed28a6f in __CFRunLoopRun ()
    #37	0x000000010ed2830b in CFRunLoopRunSpecific ()
    #38	0x000000011456ba73 in GSEventRunModal ()
    #39	0x000000010c1010b7 in UIApplicationMain ()
    #40	0x000000010af3bdf7 in main at /Users/brindy/Projects/Personal/CrashSample/CrashSample/AppDelegate.swift:12
    #41	0x000000011063b955 in start ()
    

    Hopefully it's something, I've done. Apologies in advance if it is.

    If not, let me know if there's anything I can help to debug/fix.

    Thanks in a advance!

    CrashSample.zip

    bug 
    opened by brindy 8
  • Add Prebuilt Binary For Carthage

    Add Prebuilt Binary For Carthage

    It would be nice to have prebuilt binaries attached to releases. This allows Carthage to pull those files rather than building from source each time. This is especially useful in CI environments and would help reduce build times.

    enhancement delayed 
    opened by jakewelton 5
  • Support for Swift 4.2 and iOS 12

    Support for Swift 4.2 and iOS 12

    Hello, there is an error in the code when you run the app on the simulator, that is: the case is no longer recognized when the app is on the simulator. All is returned with "notAvailable"

    bug help wanted 
    opened by furiosFast 4
  • iPhone X not being detected

    iPhone X not being detected

    I am currently trying to determine if the phone being used is an iPhone x within a collectionview & when i run the iPhone X in the simulator, it running the default code rather than the iPhoneX code, any idea as to why this is happening? Here is the code.

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
            
            let deviceType = UIDevice.current.deviceType
            
            switch deviceType {
            case .iPhoneX:
    print("is this the iPhone x?")
                if index == 1 || index == 3 {
                    width = (collectionView.bounds.width)
                } else {
                    width = (collectionView.bounds.width) / 5
                }
            default:
    
                if index == 1 || index == 3 {
    print("this is not the iphone x")
                    width = (collectionView.bounds.height)
                } else {
                    width = (collectionView.bounds.height) / 3
                }
                
                
            }
            
            return CGSize(width:width, height:width)
        }
    

    So it appears that there is a separate device for the simulator, how exactly am I supposed to test code on an iPhone X if this is unable to detect the simulator type?

    opened by asaxionis 3
  • Refactored Enum Init

    Refactored Enum Init

    By adding the variable identifiers, this ensures that, when a new device type is added, the compiler will prompt the addition of the possible identifiers. This also makes DeviceType more testable

    opened by codytwinton 3
  • Identifier for iphone 6s and 6s+ are mixed up

    Identifier for iphone 6s and 6s+ are mixed up

    For some reason iPhone7,2 is a the iPhone 6 and iPhone7,1 is the iPhone 6 plus, but iPhone8,2 is NOT the iPhone 6s, but the iPhone 6s plus. I don't know why apple stopped following its own pattern here, but as a result, 6s is identified as 6s+ and 6s+ is identified as a 6s. Ref: https://www.theiphonewiki.com/wiki/Models

    opened by iamZoltanVaradi 3
  • Added podspec

    Added podspec

    Need to add a tag 0.3.1 You also need to register for a cocoapods account to push changes https://guides.cocoapods.org/making/getting-setup-with-trunk

    opened by efremidze 3
  • Add support for the new iPhone SE

    Add support for the new iPhone SE

    It's a bit unclear whether it should be called iPhone SE or iPhone SE (2nd Gen), as Apple just uses iPhone SE in its marketing. But it is helpful to be able to tell the difference between the two models.

    I also added tests for the last falls iPhones as they were missing.

    opened by oliverkulpakko 2
  • Today Extension warning

    Today Extension warning

    I'm using your library in Today Extension. It works great, but there is a bit problem that XCode always shows this warning:

    linking against a dylib which is not safe for use in application extensions: /Users/xxx/Projects/Test/Carthage/Build/iOS/Device.framework/Device
    

    I create a test project, which might help you check this issue easier. Also I find out a solution here that might help to fix: https://stackoverflow.com/a/52995169/2082851

    Test.zip

    Hope we could fix it soon. Thank you for a useful library!

    opened by nahung89 2
  • Support iPad 5th and 6th

    Support iPad 5th and 6th

    Hello!

    The UIDeviceExtension.swift file does not appear to return accurate values for ipad 5th generation and ipad 6th generation. I would appreciate it if you add these two devices.

    Thanks!

    opened by madhwang 2
  • Outdated podspec

    Outdated podspec

    Hi,

    Please update the podspec file with a new version number. Downloading the library straight from CocoaPods pulls down an old version which doesn't include the newly released devices.

    I would open a PR but I don't know the versioning system you use.

    opened by Isuru-Nanayakkara 3
  • Enabling Travis Builds for PRs

    Enabling Travis Builds for PRs

    I'd like to enable Travis Builds on the submission of PRs, but I do not have access to Johannes Schickling's Travis CI account. @schickling - Would you enable Travis builds?

    Cc: @igorkislyuk

    enhancement 
    opened by codytwinton 1
Releases(1.2.2)
Owner
Johannes Schickling
🚀 Founder of @prisma 💾 Application developer 🙌 Cutting edge technology enthusiast
Johannes Schickling
Thingy - A modern device detection and querying library.

Thingy A modern device detection and querying library. Features Swift 5 support Modern syntax Documentation Device detection Device family detection D

Bojan Dimovski 58 Oct 5, 2022
Light weight tool for detecting the current device and screen size written in swift.

Device detect the current  device model and screen size. Installation CocoaPods Device is available through CocoaPods. To install it, simply add the

Lucas Ortis 1.5k Dec 28, 2022
Launch JIT enabled iOS app with a second iOS device

Jitterbug This app uses libimobiledevice and WiFi pairing to use one iOS device to launch apps with the debugger on another iOS device. This "tethered

null 645 Jan 6, 2023
Inspect the iOS 15 App Activity Data directly on device.

AppActivityViewer About AppActivityViewer helps to inspect the iOS 15 App Activity Data easily on device. Choose App Activity at share sheet after cli

CJ 15 Mar 30, 2022
Super-lightweight library to detect used device

Device.swift Super-lightweight library to detect used device Device.swift extends the UIDevice class by adding a property: var deviceType: DeviceType

Johannes Schickling 219 Nov 17, 2022
Detect-a-Beacon - An educational application using Apple iBeacon technology to detect beacons

Detect-a-Beacon An educational application using Apple iBeacon technology to det

NIKOLAY NIKITIN 1 Aug 9, 2022
📴 SoundModeManager 📳 Detect silent / ring mode on iOS device

?? SoundModeManager ?? Detect silent / ring mode on the device. Installation CocoaPods Usage Documentation License ?? Installation CocoaPods For usage

Yurii Lysytsia 4 Oct 4, 2022
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Easy way to detect device environment: Device model and version Screen resolution Interface orientation iOS version Battery state Environment Helps to

Anatoliy Voropay 582 Dec 25, 2022
A realistic reflective shimmer to SwiftUI Views that uses device orientation. Position any View relative to device orientation to appear as if through a window or reflected by the screen.

A 3d rotation effect that uses Core Motion to allow SwiftUI views to appear projected in a specific direction and distance relative to the device in r

Ryan Lintott 235 Dec 30, 2022
Simulate any device and settings on one simulator or device.

SwiftUI-Simulator Enables the following settings without settings or restarting the simulator or real device. Any device screen Light/Dark mode Locale

Yusuke Hosonuma 70 Dec 19, 2022
Simple library to detect motion type (walking, running, automotive) and count users steps. This library will make motion detection much more easily.

SOMotionDetector Simple library to detect motion for iOS by arturdev . Based on location updates and acceleration. ###Requierments iOS > 6.0 Compatibl

Artur  Mkrtchyan 1.1k Nov 25, 2022
Super lightweight library that helps you to localize strings, even directly in storyboards!

Translatio Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 9 or higher. Swi

Andrea Mario Lufino 19 Jan 29, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

Envoy 540 Dec 15, 2022
SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❤️ by Mahmoud Hussein SwiftUINavigator is a lightwe

OpenBytes 22 Dec 21, 2022
Lightweight Cocoa library for detecting the running device's model and screen size.

Lightweight Cocoa library for detecting the running device's model and screen size. With the newer  devices, developers have more work to do. This li

Sebastian Dobrincu 1.3k Nov 24, 2022
Super lightweight DB written in Swift.

Use of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. Pencil makes us store these values more easily.

Naruki Chigira 88 Oct 22, 2022
Super lightweight web framework in Swift based on SWSGI

Ambassador Super lightweight web framework in Swift based on SWSGI Features Super lightweight Easy to use, designed for UI automatic testing API mocki

Envoy 170 Nov 15, 2022
Super lightweight web framework in Swift based on SWSGI

Ambassador Super lightweight web framework in Swift based on SWSGI Features Super lightweight Easy to use, designed for UI automatic testing API mocki

Envoy 170 Nov 15, 2022