Coder Social home page Coder Social logo

devicekit / devicekit Goto Github PK

View Code? Open in Web Editor NEW
4.4K 73.0 425.0 654 KB

DeviceKit is a value-type replacement of UIDevice.

License: MIT License

Swift 78.37% Ruby 1.72% Shell 0.04% Python 19.87%
swift ios tvos device device-family simulator battery-level battery-state swiftpm hacktoberfest

devicekit's Issues

isZoomed() Not working

I tried out the:

public var isZoomed: Bool {
    return UIScreen.main().scale < UIScreen.main().nativeScale
}

But it will never return true even if I have my device on zoomed.
My device is a real iphone 6 Plus/iOS 10.1

Add static var to get all plus devices

Talking about phones, The plus versions can have some different spacing or behaviours than "regular" sized devices (4.7inches and below).

In our project, we have some complex custom designs and currently we have this line of code there:

Device().isOneOf([.iPhone6Plus, .iPhone6sPlus, .iPhone7Plus, .iPhone8Plus])

Which is not ideal, because we have to manually update it everytime we have new iPhones released.
Instead, it would be nice to have something like:

Device().isOneOf(Device.allPlusPhones)

What do you think? If you agree, I can create a small PR adding the method + a small test

Needs update for Xcode 7.1 Swift 2.1

Add:
default: self = .Unspecified

Change To:
let batteryLevel = Double(round(100.0 * (UIDevice.currentDevice().batteryLevel * 100.0)) / 100.0) // rounded, with 2 digits precision

Get the `Device` as string

Hey,

I would like to store the outcome of print(Device) in a variable. Is that possible?

Best regards

Device.allPhonesIncludingSimulators

If theres an allPhones option it seems silly to have to add in a bunch of extras in order to support simulators. Adding an additional static var for simulators would be super helpful for me as i use these all over my project for UI layout.

Carthage update issue with XCode 9

Hi!

Got an issue

Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/Andrey/MFO_BOX/Carthage/Checkouts/DeviceKit/DeviceKit.xcodeproj -scheme DeviceKit -configuration Release -derivedDataPath /Users/Andrey/Library/Caches/org.carthage.CarthageKit/DerivedData/8.3.3_8E3004b/DeviceKit/1.3.2 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/Andrey/MFO_BOX/Carthage/Checkouts/DeviceKit)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/4j/220h75g17k32pn1_6t59tc8w0000gp/T/carthage-xcodebuild.ySawYr.log

I have 2 XCode versions on machine: 8.3.3 and 9 GM. It happened when I tried to update carthage with DeviceKit v. 1.4.0 at Cartfile. Downgrate to v. 1.2.3 only help me, but I need to get support for new devices

All devices available everywhere

I am working on my shared framework (iOS/tvOS) and tried to use DeviceKit inside but then I found, that i have to use #if os(iOS) ... around DeviceKit calls using because they are already around funcs and vars inside DeviceKit. Wouldn't be better to have all devices available everywhere? I would like to use it for example then like this:

switch device {
case iPhone6, iPhone6s: ...
case AppleTV4: ...
}

Currently I have to write this, because not all funcs and vars are available everywhere

switch device {
#if os(iOS)
case iPhone6, iPhone6s: ...
#elseif os(tvOS)
case AppleTV4: ...
#end
}

I know that the tvOS code probably should not be present in iOS version and vice versa, but this could decide DeviceKit inside implementation. Or is there any issue with Simulator detection or something else?

iPad Pro not working?

Weird, tried this on iPad Pro Simulator but it is returning false?
print(Device().isOneOf([Device.iPadPro]))

enum for iPad Pro size?

I looked at the code but didn't see anything to differentiate between iPad Pro size.

How do we do this?

CarPlay

Hi man, long time no see!

I'm getting a compiling problem when using 0.3.1 (that first included CarPlay in

private init() {
            switch UIDevice.currentDevice().userInterfaceIdiom {
            case .Pad:          self = .Pad
            case .Phone:        self = .Phone
            case .TV:           self = .TV
            case .Unspecified:  self = .Unspecified
            }
        }

But since CarPlay has been included there, the app fails when building (as it doesn't exist) and I have to stick to 0.3.0.

I wouldn't like to miss future updates of this repo because of this :D

Thanks!

Installed the pod but what should I import?

Hey there,

I'm trying to use this framework. I installed the pod (Swift 3.0) and now I'm trying to use the actual framework. When I write in my class file: let device = Device() it comes up with an error: "Use of an unresolved identifier "Device". So my question is how I can fix that?

Carthage build still not working with version 1.3.3

Hi, here is the log from carthage update DeviceKit --platform ios --cache-builds

*** Checking out DeviceKit at "1.3.3"
*** xcodebuild output can be found in /var/folders/9w/ng8hkhns2lb5hqdcw85vm5kc0000gn/T/carthage-xcodebuild.b8QBr5.log
*** Invalid cache found for DeviceKit, rebuilding with all downstream dependencies
*** Building scheme "DeviceKit" in DeviceKit.xcodeproj
Build Failed
Task failed with exit code 65:
/usr/bin/xcrun xcodebuild -project /Users/[myuser]/[myproject]

/Carthage/Checkouts/DeviceKit/DeviceKit.xcodeproj -scheme DeviceKit -configuration Release -derivedDataPath /Users/[myuser]/Library/Caches/org.carthage.CarthageKit/DerivedData/8.3.3_8E3004b/DeviceKit/1.3.3 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /Users/[myuser]/[myproject]/Carthage/Checkouts/DeviceKit)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/9w/ng8hkhns2lb5hqdcw85vm5kc0000gn/T/carthage-xcodebuild.b8QBr5.log

I reverted to 1.2.3 for the moment.

Expand on Simulator Devices

Hi,

I was wondering if you had any thoughts on expanding the simulator device models? I ran into a scenario where I needed to inspect the device to see if it was an iPhone 6 plus or 6s Plus and I noticed that the simulator only returns Simulator.

What do you think about making a Bool flag that is something like "Is Simulator" and allowing the simulator to resolve to the model that is simulating?

the model name of the simulator can be retrieved by using:

String(UTF8String: getenv("SIMULATOR_MODEL_IDENTIFIER"))

Safer logic in `Device().isPad`

Newly introduced Apple devices might report incorrectly from Device().isPad.

In my case, I had not updated DeviceKit and the newly introduced iPad (7,4) was not being handled properly.

If developers are not careful, this might cause critical bugs.

I think it might be safer if the logic is such that there is at least a 'fallback' for APIs such as isPad. For example if the device lookup (in Device.swift.gyb ) fails, the isPad logic falls back to native Apple APIs (e.g. userInterfaceIdiom).

Crashes when searching for device that doesn't exist

We were using a older version of the library in our app and hadn't updated it in awhile and then the iPhone 7 came out and we still didn't update...It couldn't find the identifier in the list and so it attempted to try and guess it was a Simulator which it wasn't and so it crashed because of the force unwrap here it would be nice if the case where a device doesn't exist in the list that it didn't crash but returned a unknown device or handled things in a better way

xcodebuild: error Scheme DeviceKit-iOS is not currently configured for the build action

A shell task (/usr/bin/xcrun xcodebuild -project /Carthage/Checkouts/DeviceKit/DeviceKit.xcodeproj -scheme DeviceKit-iOS -configuration Release CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -showBuildSettings) failed with exit code 66:
xcodebuild: error: Scheme DeviceKit-iOS is not currently configured for the build action.

Getting the error above after running a carthage update. Running carthage update --platform iOS does the same. Recently updated to XCode 8.0
My cartfile looks like this:

github "dennisweissmann/DeviceKit" ~> 1.0

Build failure on Carthage due to lack of formatting tools

swiftformat not found. Trying to install it via Homebrew...
Installing swiftformat via homebrew failed. Homebrew not found. Aborting.

External dependencies that format code or lint code should not be required for creating a release build.

As it stands, I can't build DeviceKit using Carthage.

Xcode 8.3.3 - Swift Language version error

I'm getting this when using Carthage, or building master directly from a git clone:

Check dependencies

“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.


I think the project file for master is defaulting to Swift 4.0, where it should be changed to Swift 3.0. Should I be using the "swift-3" branch?

Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift.

I tried to install it through cocoapod. Installation went successful but my xcode force me to convert swift code i tried doing it later i got 18 errors. Then i deintegrate it pod from my project and again tried installing it. However, process was successful again but this time i didnt choose conversion of swift syntax on which i got this error: " Check dependecies: Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly." What should i do next ?

Device's PPI

iOS has no public API for getting the device's PPI.
It seems the only way is to hardcode the values based on the device.

Support for zoomed displays

When dealing with interfaces for different device sizes I would like to know what scale the user is using for the display i.e. Standard or Zoomed

Because the zoomed display on an iPhone 6 has the same resolution as an iPhone 5 the interface will not layout correctly.

It would be useful to something such as:

let Device = Device()
if device.isZoomed {}

Thanks!

deployment target is 9.1

Module file's minimum deployment target is ios9.1 v9.1: /Carthage/Build/iOS/DeviceKit.framework/Modules/DeviceKit.swiftmodule/arm64.swiftmodule

Could you change the deployment target to 8.0 as indicated in the README, so someone could use the Carthage version for projects which should support iOS version before 9.1?
Thanks!

"Module compiled with swift 4.0 cannot be imported in swift 3.1" error on build

Yesterday I tried Xcode9 beta. Now I want to go back using Xcode 8 but I faced this error on project build for DeviceKit and only for DeviceKit:

Module compiled with swift 4.0 cannot be imported in swift 3.1

The framework installation is made by Carthage. Building DeviceKit project on Xcode 8 works fine. But not on my project. I've tried a lot of things from deleting all Carthage and rebuild all, cleaning project, removing Derived Data... But the problem is still here. And only on DeviceKit.

So I wonder if there is some configuration in DeviceKit to be made to solve it.

CocoaPods instruction for Swift 3.0 in README doesn't work

The CocoaPods instruction

pod 'DeviceKit', '~> 1.0'

doesn't work.

This is due to a bug in CocoaPods ... I currently cannot submit any new versions to the CocoaPods trunk because it doesn't lint. The error I get is:

=== CLEAN TARGET DeviceKit OF PROJECT Pods WITH CONFIGURATION Release ===

Check dependencies
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for >targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** CLEAN FAILED **

The following build commands failed:
Check dependencies
(1 failure)
=== BUILD TARGET DeviceKit OF PROJECT Pods WITH CONFIGURATION Release ===

Check dependencies
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

** BUILD FAILED **

The following build commands failed:
Check dependencies
(1 failure)
-> DeviceKit (1.0.0)
- ERROR | xcodebuild: Returned an unsuccessful exit code.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.

/Users/dennis/.rvm/gems/ruby-2.3.1/gems/cocoapods-1.1.0.rc.1/lib/cocoapods/command/spec/lint.rb:77:in run' /Users/dennis/.rvm/gems/ruby-2.3.1@global/gems/claide-1.0.0/lib/claide/command.rb:334:inrun'
/Users/dennis/.rvm/gems/ruby-2.3.1/gems/cocoapods-1.1.0.rc.1/lib/cocoapods/command.rb:50:in run' /Users/dennis/.rvm/gems/ruby-2.3.1/gems/cocoapods-1.1.0.rc.1/bin/pod:55:in<top (required)>'
/Users/dennis/.rvm/gems/ruby-2.3.1/bin/pod:23:in load' /Users/dennis/.rvm/gems/ruby-2.3.1/bin/pod:23:in

'
/Users/dennis/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in eval' /Users/dennis/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in'

SWIFT_VERSION is set to 3.0.

If anyone has any insights on this and knows how to work around please let me know! Thanks! 🙏

Pod / Carthage

I think this is handy, you could make a pod to make it available easier and it should be simple as it's just one file without dependencies.

That would be nice for sure!

Carthage won't build DeviceKit.framework

Running carthage update --platform iOS results in the following error:

*** Building scheme "DeviceKit" in DeviceKit.xcodeproj Failed to write to /Users/ryan/Developer/storefront-ios/Carthage/Build/iOS/DeviceKit.framework: Error Domain=NSCocoaErrorDomain Code=260 "The file “DeviceKit.framework” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Users/ryan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.0_9A235/DeviceKit/1.3.0/Build/Products/Release-iphoneos/DeviceKit.framework, NSFilePath=/Users/ryan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.0_9A235/DeviceKit/1.3.0/Build/Products/Release-iphoneos/DeviceKit.framework, NSUnderlyingError=0x7fdbf3c1cb40 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Versions:
macOS Sierra 10.12.6
Xcode 9.0 (9A235)
Carthage 0.25.0
DeviceKit 1.3.0 and 1.3.1

Cannot build with Carthage

Using Carthage 0.15, I get the following error when trying to build for iOS:

*** Building scheme "DeviceKit-iOS" in DeviceKit.xcodeproj
2016-03-09 11:02:52.948 xcodebuild[15957:23586646] [MT] PluginLoading: Required plug-in compatibility UUID F41BD31E-2683-44B8-AE7F-5F09E919790E for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPodUI.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-03-09 11:02:52.948 xcodebuild[15957:23586646] Failed to load plugin at: /Users/schjonhaug/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPodUI.xcplugin, skipping.  Reason for failure: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal arm64 /Users/schjonhaug/Development/rikstv-jr./Carthage/Checkouts/DeviceKit/Source/Device.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
/Users/schjonhaug/Development/rikstv-jr./Carthage/Checkouts/DeviceKit/Source/Device.swift:352:19: error: enum case 'CarPlay' not found in type 'UIUserInterfaceIdiom'
A shell task failed with exit code 65:
2016-03-09 11:02:52.948 xcodebuild[15957:23586646] [MT] PluginLoading: Required plug-in compatibility UUID F41BD31E-2683-44B8-AE7F-5F09E919790E for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPodUI.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2016-03-09 11:02:52.948 xcodebuild[15957:23586646] Failed to load plugin at: /Users/schjonhaug/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPodUI.xcplugin, skipping.  Reason for failure: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
** BUILD FAILED **


The following build commands failed:
    CompileSwift normal arm64 /Users/schjonhaug/Development/rikstv-jr./Carthage/Checkouts/DeviceKit/Source/Device.swift
    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

UserInterfaceIdiom CarPlay problem

The current pod version is not building for me, saying:

Enum case 'CarPlay' not found in type 'UIUserInterfaceIdiom'

I couldn't find anything about the CarPlay enum in the apple docs for UIUserInterfaceIdiom

You don't seem to have a license

Hey you don't seem to have a license anywhere. Is it alright if i use your device.swift file in my project for commercial purposes as long as i leave the file as it is without removing any comments or code?

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.