| สาขา | รุ่น |
|---|---|
| ผู้เชี่ยวชาญ | ≥ 2.0 |
| Swift 4 - 4.2 | ≥ 1.3 <1.13 |
| Swift 3 | ≥ 1.0 <1.3 |
| Swift 2.3 | <1.0 |
DeviceKit เป็นการแทนที่ UIDevice ประเภทมูลค่า
ดูการเปลี่ยนแปลงโดยละเอียดของเราสำหรับคุณสมบัติล่าสุดการปรับปรุงและการแก้ไขข้อบกพร่อง
สามารถติดตั้ง 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 submodule โดยการรัน:
$ git submodule add https://github.com/devicekit/DeviceKit.gitก่อนอื่นให้แน่ใจว่าได้นำเข้าเฟรมเวิร์ก:
import DeviceKitนี่คือตัวอย่างการใช้งานบางส่วน อุปกรณ์ทั้งหมดมีให้บริการเป็นเครื่องจำลอง:
. iPhone6 => . simulator ( . iPhone6 )
. iPhone6s => . simulator ( . iPhone6s )คุณสามารถลองตัวอย่างเหล่านี้ในสนามเด็กเล่น
บันทึก:
หากต้องการลองใช้ DeviceKit ในสนามเด็กเล่นให้เปิด
DeviceKit.xcworkspaceและสร้าง devicekit.framework สำหรับการจำลองใด ๆ ก่อนโดยเลือก "deviceKit" เป็นรูปแบบปัจจุบันของคุณ
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 หรือแยกออกจากแอพ Simulator ที่รวมกับ Xcode
หากคุณต้องการคุณสมบัติเฉพาะที่คุณต้องการนำไปใช้หรือหากคุณประสบข้อผิดพลาดโปรดเปิดปัญหา หากคุณขยายฟังก์ชันการทำงานของอุปกรณ์ด้วยตัวคุณเองและต้องการให้ผู้อื่นใช้มันด้วยโปรดส่งคำขอดึง
รายชื่อผู้คนที่มีส่วนร่วมในโครงการนี้มีอยู่ที่นี่ DeviceKit จะไม่เป็นอย่างที่คุณไม่มี! ขอบคุณมาก!