Giter Site home page Giter Site logo

device.swift's Introduction

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

device.swift's People

Contributors

alexszilagyi avatar apoorvkhatreja avatar brunokoga avatar codexprojects avatar codytwinton avatar eddieespinal avatar efremidze avatar hboon avatar igorkislyuk avatar isapozhnik avatar joragan avatar laptopmini avatar mathieurobidoux avatar mlight3 avatar mukeshthawani avatar oliverkulpakko avatar rex3du avatar ryanramchandar avatar schickling avatar stevemoser avatar zhouhao27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

device.swift's Issues

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!

EXC_BAD_ACCESS for EnumProtocol .all

I've started to get a crash for the EnumProtocol .all implementation. It's crashing on line 235 in UIDeviceExtension.swift. I think this has started happening with the latest version of Xcode (Version 9.3 (9E145)).

Test all seem to run fine, however, once the library is integrated into a project, trying to access something such as deviceType, causes this runtime crash.

I've integrated using Carthage. Not sure if this problem also happens when using Cocoapods.

I've built an example app, demonstrating this problem. You can find it here: https://github.com/jwelton/Device.swift/tree/example-app

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?

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.

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!

Miss iPhone 7 and iPhone 7 plus identifier

In the init(), it's missing iPhone 7 and iPhone 7 plus identifier. I noticed that there is iPhone 7 and iPhone7Plus case, however, it won't show the correct String if the identifier is missing.

I requested a pull request to add them in. #28

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

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.

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.