| 나뭇가지 | 버전 |
|---|---|
| 주인 | ≥ 2.0 |
| 스위프트 4-4.2 | ≥ 1.3 <1.13 |
| 스위프트 3 | ≥ 1.0 <1.3 |
| 스위프트 2.3 | <1.0 |
DeviceKit 은 UIDevice 의 값 유형 교체입니다.
최신 기능, 개선 및 버그 수정에 대해서는 자세한 ChangeLog를 참조하십시오.
DeviceKit은 다양한 방식으로 설치할 수 있습니다.
pod 'DeviceKit' , '~> 5.2' pod 'DeviceKit' , '3.2' pod 'DeviceKit' , '~> 1.3' pod 'DeviceKit' , '~> 1.2.3' pod 'DeviceKit' , :git => 'https://github.com/devicekit/DeviceKit.git' , :branch => 'swift-2.3-unsupported'dependencies: [
. package ( url : " https://github.com/devicekit/DeviceKit.git " , from : " 4.0.0 " ) ,
/// ...
] dependencies: [
. package ( url : " https://github.com/devicekit/DeviceKit.git " , from : " 3.2.0 " ) ,
/// ...
] github "devicekit/DeviceKit" ~> 4.0
github "devicekit/DeviceKit" ~> 3.2
github "devicekit/DeviceKit" ~> 1.3
github "devicekit/DeviceKit" ~> 1.2.3
github "devicekit/DeviceKit" "swift-2.3-unsupported"
수동으로 설치하려면 DeviceKit 프로젝트를 Xcode의 앱 프로젝트로 드래그하십시오. 또는 실행하여 git 하위 모듈로 추가하십시오.
$ git submodule add https://github.com/devicekit/DeviceKit.git먼저 프레임 워크를 가져 오십시오.
import DeviceKit여기에 몇 가지 사용 예가 있습니다. 모든 장치는 시뮬레이터로도 제공됩니다.
. iPhone6 => . simulator ( . iPhone6 )
. iPhone6s => . simulator ( . iPhone6s )이 예제를 놀이터에서 시도해 볼 수 있습니다.
메모:
놀이터에서 DeviceKit을 시도하려면
DeviceKit.xcworkspace열고 현재 체계로 "DeviceKit"을 선택하여 모든 시뮬레이터 용 DeviceKit.Framework를 구축하십시오.
let device = Device . current
print ( device ) // prints, for example, "iPhone 6 Plus"
if device == . iPhone6Plus {
// Do something
} else {
// Do something else
} let device = Device . current
if device . isPod {
// iPods (real or simulator)
} else if device . isPhone {
// iPhone (real or simulator)
} else if device . isPad {
// iPad (real or simulator)
} let device = Device . current
if device . isSimulator {
// Running on one of the simulators(iPod/iPhone/iPad)
// Skip doing something irrelevant for Simulator
} let device = Device . current
switch device {
case . simulator ( . iPhone6s ) : break // You're running on the iPhone 6s simulator
case . simulator ( . iPadAir2 ) : break // You're running on the iPad Air 2 simulator
default : break
} let groupOfAllowedDevices : [ Device ] = [ . iPhone6 , . iPhone6Plus , . iPhone6s , . iPhone6sPlus , . simulator ( . iPhone6 ) , . simulator ( . iPhone6Plus ) , . simulator ( . iPhone6s ) , . simulator ( . iPhone6sPlus ) . simulator ( . iPhone8 ) , . simulator ( . iPhone8Plus ) , . simulator ( . iPhoneX ) , . simulator ( . iPhoneXS ) , . simulator ( . iPhoneXSMax ) , . simulator ( . iPhoneXR ) ]
let device = Device . current
if device . isOneOf ( groupOfAllowedDevices ) {
// Do your action
}메모:
현재 배터리 상태를 얻으려면
UIDevice.current.isBatteryMonitoringEnabled를true로 설정해야합니다. 코드의 문제를 피하기 위해 현재 설정을 읽고 우리가 완료했을 때 이전의 내용으로 재설정합니다.
if device . batteryState == . full || device . batteryState >= . charging ( 75 ) {
print ( " Your battery is happy! ? " )
}if device . batteryLevel >= 50 {
install_iOS ( )
} else {
showError ( )
}if device . batteryState . lowPowerMode {
print ( " Low Power mode is enabled! ? " )
} else {
print ( " Low Power mode is disabled! ? " )
}if device . isGuidedAccessSessionActive {
print ( " Guided Access session is currently active " )
} else {
print ( " No Guided Access session is currently active " )
}if device . screenBrightness > 50 {
print ( " Take care of your eyes! " )
}if Device . volumeAvailableCapacityForOpportunisticUsage ?? 0 > Int64 ( 1_000_000 ) {
// download that nice-to-have huge file
}
if Device . volumeAvailableCapacityForImportantUsage ?? 0 > Int64 ( 1_000 ) {
// download that file you really need
} 모든 모델 식별자는 다음 웹 사이트에서 가져옵니다. https://www.theiphonewiki.com/wiki/models 또는 Xcode와 함께 번들 된 시뮬레이터 앱에서 추출됩니다.
구현하려는 특정 기능이 필요하거나 버그를 경험 한 경우 문제를여십시오. DeviceKit의 기능을 직접 확장하고 다른 사람들도 사용하기를 원한다면 풀 요청을 제출하십시오.
이 프로젝트에 기여한 사람들의 전체 목록은 여기에서 제공됩니다. Devicekit은 당신 없이는 그것이 무엇인지가 아닙니다! 매우 감사합니다!