@@ -1254,3 +1254,91 @@ extension Device {
1254
1254
}
1255
1255
}
1256
1256
#endif
1257
+
1258
+ #if os(iOS)
1259
+ // MARK: - Cameras
1260
+ extension Device {
1261
+
1262
+ public enum CameraTypes {
1263
+ case normal
1264
+ case telephoto
1265
+ }
1266
+
1267
+ /// Returns an array of the types of cameras the device has
1268
+ public var cameras : [ CameraTypes ] {
1269
+ switch self {
1270
+ case . iPodTouch5: return [ . normal]
1271
+ case . iPodTouch6: return [ . normal]
1272
+ case . iPhone4: return [ . normal]
1273
+ case . iPhone4s: return [ . normal]
1274
+ case . iPhone5: return [ . normal]
1275
+ case . iPhone5c: return [ . normal]
1276
+ case . iPhone5s: return [ . normal]
1277
+ case . iPhone6: return [ . normal]
1278
+ case . iPhone6Plus: return [ . normal]
1279
+ case . iPhone6s: return [ . normal]
1280
+ case . iPhone6sPlus: return [ . normal]
1281
+ case . iPhone7: return [ . normal]
1282
+ case . iPhoneSE: return [ . normal]
1283
+ case . iPhone8: return [ . normal]
1284
+ case . iPhoneXR: return [ . normal]
1285
+ case . iPad2: return [ . normal]
1286
+ case . iPad3: return [ . normal]
1287
+ case . iPad4: return [ . normal]
1288
+ case . iPadAir: return [ . normal]
1289
+ case . iPadAir2: return [ . normal]
1290
+ case . iPad5: return [ . normal]
1291
+ case . iPad6: return [ . normal]
1292
+ case . iPadAir3: return [ . normal]
1293
+ case . iPadMini: return [ . normal]
1294
+ case . iPadMini2: return [ . normal]
1295
+ case . iPadMini3: return [ . normal]
1296
+ case . iPadMini4: return [ . normal]
1297
+ case . iPadMini5: return [ . normal]
1298
+ case . iPadPro9Inch: return [ . normal]
1299
+ case . iPadPro12Inch: return [ . normal]
1300
+ case . iPadPro12Inch2: return [ . normal]
1301
+ case . iPadPro10Inch: return [ . normal]
1302
+ case . iPadPro11Inch: return [ . normal]
1303
+ case . iPadPro12Inch3: return [ . normal]
1304
+ case . iPhone7Plus: return [ . normal, . telephoto]
1305
+ case . iPhone8Plus: return [ . normal, . telephoto]
1306
+ case . iPhoneX: return [ . normal, . telephoto]
1307
+ case . iPhoneXS: return [ . normal, . telephoto]
1308
+ case . iPhoneXSMax: return [ . normal, . telephoto]
1309
+ default : return [ ]
1310
+ }
1311
+ }
1312
+
1313
+ /// All devices that feature a camera
1314
+ public static var allDevicesWithCamera : [ Device ] {
1315
+ return [ . iPodTouch5, . iPodTouch6, . iPhone4, . iPhone4s, . iPhone5, . iPhone5c, . iPhone5s, . iPhone6, . iPhone6Plus, . iPhone6s, . iPhone6sPlus, . iPhone7, . iPhone7Plus, . iPhoneSE, . iPhone8, . iPhone8Plus, . iPhoneX, . iPhoneXS, . iPhoneXSMax, . iPhoneXR, . iPad2, . iPad3, . iPad4, . iPadAir, . iPadAir2, . iPad5, . iPad6, . iPadAir3, . iPadMini, . iPadMini2, . iPadMini3, . iPadMini4, . iPadMini5, . iPadPro9Inch, . iPadPro12Inch, . iPadPro12Inch2, . iPadPro10Inch, . iPadPro11Inch, . iPadPro12Inch3]
1316
+ }
1317
+
1318
+ /// All devices that feature a normal camera
1319
+ public static var allDevicesWithNormalCamera : [ Device ] {
1320
+ return [ . iPodTouch5, . iPodTouch6, . iPhone4, . iPhone4s, . iPhone5, . iPhone5c, . iPhone5s, . iPhone6, . iPhone6Plus, . iPhone6s, . iPhone6sPlus, . iPhone7, . iPhone7Plus, . iPhoneSE, . iPhone8, . iPhone8Plus, . iPhoneX, . iPhoneXS, . iPhoneXSMax, . iPhoneXR, . iPad2, . iPad3, . iPad4, . iPadAir, . iPadAir2, . iPad5, . iPad6, . iPadAir3, . iPadMini, . iPadMini2, . iPadMini3, . iPadMini4, . iPadMini5, . iPadPro9Inch, . iPadPro12Inch, . iPadPro12Inch2, . iPadPro10Inch, . iPadPro11Inch, . iPadPro12Inch3]
1321
+ }
1322
+
1323
+ /// All devices that feature a telephoto camera
1324
+ public static var allDevicesWithTelephotoCamera : [ Device ] {
1325
+ return [ . iPhone7Plus, . iPhone8Plus, . iPhoneX, . iPhoneXS, . iPhoneXSMax]
1326
+ }
1327
+
1328
+ /// Returns whether or not the current device has a camera
1329
+ public var hasCamera : Bool {
1330
+ return !self . cameras. isEmpty
1331
+ }
1332
+
1333
+ /// Returns whether or not the current device has a normal camera
1334
+ public var hasNormalCamera : Bool {
1335
+ return self . cameras. contains ( . normal)
1336
+ }
1337
+
1338
+ /// Returns whether or not the current device has a telephoto camera
1339
+ public var hasTelephotoCamera : Bool {
1340
+ return self . cameras. contains ( . telephoto)
1341
+ }
1342
+
1343
+ }
1344
+ #endif
0 commit comments