| فرع | الإصدارات |
|---|---|
| يتقن | ≥ 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 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 أو استخراجها من تطبيق المحاكاة المجمعة مع Xcode.
إذا كنت بحاجة إلى ميزة محددة تريد تنفيذها أو إذا واجهت خطأ ، فيرجى فتح مشكلة. إذا قمت بتوسيع وظيفة DeviceKit بنفسك وتريد أن يستخدمها الآخرون أيضًا ، فيرجى إرسال طلب سحب.
تتوفر القائمة الكاملة للأشخاص الذين ساهموا في هذا المشروع هنا. DeviceKit لن يكون ما هو بدونك! شكراً جزيلاً!