forked from erica/uidevice-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIDevice-Hardware.m
638 lines (569 loc) · 20.1 KB
/
UIDevice-Hardware.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
// Thanks to Emanuele Vulcano, Kevin Ballard/Eridius, Ryandjohnson, Matt Brown, etc.
// TTD: - Bluetooth? Screen pixels? Dot pitch? Accelerometer? GPS enabled/disabled
#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#import "UIDevice-Hardware.h"
@implementation UIDevice (Hardware)
/*
Platforms
iFPGA -> ??
iPhone1,1 -> iPhone 1G
iPhone1,2 -> iPhone 3G
iPhone2,1 -> iPhone 3GS
iPhone3,1 -> iPhone 4G/AT&T
iPhone3,2 -> iPhone 4G/Other Carrier
iPhone3,3 -> iPhone 4G/Other Carrier
iPod1,1 -> iPod touch 1G
iPod2,1 -> iPod touch 2G
iPod2,2 -> iPod touch 2.5G
iPod3,1 -> iPod touch 3G
iPod4,1 -> iPod touch 4G
iPad1,1 -> iPad 1G, WiFi
iPad1,? -> iPad 1G, 3G <- needs 3G owner to test
iPad2,1 -> iPad 2G
i386 -> iPhone Simulator
*/
#pragma mark sysctlbyname utils
- (NSString *) getSysInfoByName:(char *)typeSpecifier
{
size_t size;
sysctlbyname(typeSpecifier, NULL, &size, NULL, 0);
char *answer = malloc(size);
sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
free(answer);
return results;
}
- (NSString *) platform
{
return [self getSysInfoByName:"hw.machine"];
}
#pragma mark sysctl utils
- (NSUInteger) getSysInfo: (uint) typeSpecifier
{
size_t size = sizeof(int);
int results;
int mib[2] = {CTL_HW, typeSpecifier};
sysctl(mib, 2, &results, &size, NULL, 0);
return (NSUInteger) results;
}
- (NSUInteger) cpuFrequency
{
return [self getSysInfo:HW_CPU_FREQ];
}
- (NSUInteger) busFrequency
{
return [self getSysInfo:HW_BUS_FREQ];
}
- (NSUInteger) totalMemory
{
return [self getSysInfo:HW_PHYSMEM];
}
- (NSUInteger) userMemory
{
return [self getSysInfo:HW_USERMEM];
}
- (NSUInteger) maxSocketBufferSize
{
return [self getSysInfo:KIPC_MAXSOCKBUF];
}
#pragma mark file system -- Thanks Joachim Bean!
- (NSNumber *) totalDiskSpace
{
NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
return [fattributes objectForKey:NSFileSystemSize];
}
- (NSNumber *) freeDiskSpace
{
NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
return [fattributes objectForKey:NSFileSystemFreeSize];
}
#pragma mark platform type and name utils
- (NSUInteger) platformType
{
NSString *platform = [self platform];
// if ([platform isEqualToString:@"XX"]) return UIDeviceUnknown;
if ([platform isEqualToString:@"iFPGA"]) return UIDeviceIFPGA;
if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
if ([platform isEqualToString:@"iPhone2,1"]) return UIDevice3GSiPhone;
if ([platform isEqualToString:@"iPhone3,1"]) return UIDevice4GiPhone;
if ([platform isEqualToString:@"iPod1,1"]) return UIDevice1GiPod;
if ([platform isEqualToString:@"iPod2,1"]) return UIDevice2GiPod;
if ([platform isEqualToString:@"iPod2,2"]) return UIDevice2GPlusiPod;
if ([platform isEqualToString:@"iPod3,1"]) return UIDevice3GiPod;
if ([platform isEqualToString:@"iPod4,1"]) return UIDevice4GiPod;
if ([platform isEqualToString:@"iPad1,1"]) return UIDevice1GiPad;
// if ([platform isEqualToString:@"iPad2,1"]) return UIDevice2GiPad;
/*
MISSING A SOLUTION HERE TO DATE TO DIFFERENTIATE iPAD and iPAD 3G.... SORRY!
*/
if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
if ([platform hasSuffix:@"86"])
{
if ([[UIScreen mainScreen] bounds].size.width < 768)
return UIDeviceiPhoneSimulatoriPhone;
else
return UIDeviceiPhoneSimulatoriPad;
return UIDeviceiPhoneSimulator;
}
return UIDeviceUnknown;
}
- (NSString *) platformString
{
switch ([self platformType])
{
case UIDevice1GiPhone: return IPHONE_1G_NAMESTRING;
case UIDevice3GiPhone: return IPHONE_3G_NAMESTRING;
case UIDevice3GSiPhone: return IPHONE_3GS_NAMESTRING;
case UIDevice4GiPhone: return IPHONE_4G_NAMESTRING;
case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
case UIDevice1GiPod: return IPOD_1G_NAMESTRING;
case UIDevice2GiPod: return IPOD_2G_NAMESTRING;
case UIDevice3GiPod: return IPOD_3G_NAMESTRING;
case UIDevice4GiPod: return IPOD_4G_NAMESTRING;
case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
case UIDevice1GiPad : return IPAD_1G_NAMESTRING;
case UIDevice1GiPad3G : return IPAD3G_1G_NAMESTRING;
case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
case UIDeviceiPhoneSimulatoriPhone: return IPHONE_SIMULATOR_IPHONE_NAMESTRING;
case UIDeviceiPhoneSimulatoriPad: return IPHONE_SIMULATOR_IPAD_NAMESTRING;
case UIDeviceIFPGA: return IFPGA_NAMESTRING;
default: return IPOD_FAMILY_UNKNOWN_DEVICE;
}
}
#pragma mark platform capabilities
- (NSUInteger) platformCapabilities
{
switch ([self platformType])
{
case UIDevice1GiPhone:
return
(UIDeviceSupportsTelephony |
UIDeviceSupportsSMS |
UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
// UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
UIDeviceSupportsVibration |
UIDeviceSupportsBuiltInProximitySensor |
// UIDeviceSupportsAccessibility |
// UIDeviceSupportsVoiceOver |
// UIDeviceSupportsVoiceControl |
// UIDeviceSupportsPeerToPeer |
// UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth | // M68.plist says YES for this
// UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons
);
case UIDevice3GiPhone:
return
(UIDeviceSupportsTelephony |
UIDeviceSupportsSMS |
UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
// UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
UIDeviceSupportsVibration |
UIDeviceSupportsBuiltInProximitySensor |
// UIDeviceSupportsAccessibility |
// UIDeviceSupportsVoiceOver |
// UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
// UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
// UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons
);
case UIDevice3GSiPhone:
return
(UIDeviceSupportsTelephony |
UIDeviceSupportsSMS |
UIDeviceSupportsStillCamera |
UIDeviceSupportsAutofocusCamera |
UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
UIDeviceSupportsGPS |
UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
UIDeviceSupportsVibration |
UIDeviceSupportsBuiltInProximitySensor |
UIDeviceSupportsAccessibility |
UIDeviceSupportsVoiceOver |
UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons
);
case UIDevice4GiPhone:
return
(UIDeviceSupportsTelephony |
UIDeviceSupportsSMS |
UIDeviceSupportsStillCamera |
UIDeviceSupportsAutofocusCamera |
UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
UIDeviceSupportsGPS |
UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
UIDeviceSupportsVibration |
UIDeviceSupportsBuiltInProximitySensor |
UIDeviceSupportsAccessibility |
UIDeviceSupportsVoiceOver |
UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons |
UIDeviceSupportsGyroscope |
UIDeviceSupportsRetinaDisplay
);
case UIDeviceUnknowniPhone: return 0;
case UIDevice1GiPod:
return
(// UIDeviceSupportsTelephony |
// UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
// UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
// UIDeviceSupportsOPENGLES2 |
// UIDeviceSupportsBuiltInSpeaker |
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
// UIDeviceSupportsAccessibility |
// UIDeviceSupportsVoiceOver |
// UIDeviceSupportsVoiceControl |
UIDeviceSupportsBrightnessSensor |
// UIDeviceSupportsEncodeAAC |
// UIDeviceSupportsBluetooth |
// UIDeviceSupportsNike |
UIDeviceSupportsPiezoClicker
// UIDeviceSupportsVolumeButtons
);
case UIDevice2GiPod:
case UIDevice2GPlusiPod:
return
(// UIDeviceSupportsTelephony |
// UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
// UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
// UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
// UIDeviceSupportsAccessibility |
// UIDeviceSupportsVoiceOver |
// UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
// UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons
);
case UIDevice3GiPod:
return
(// UIDeviceSupportsTelephony |
// UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
// UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
UIDeviceSupportsAccessibility |
UIDeviceSupportsVoiceOver |
UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons
);
case UIDeviceUnknowniPod: return 0;
case UIDevice1GiPad:
return
(// UIDeviceSupportsTelephony |
// UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
UIDeviceSupportsAccessibility |
UIDeviceSupportsVoiceOver |
UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons |
UIDeviceSupportsEnhancedMultitouch
);
case UIDevice1GiPad3G:
return
(// UIDeviceSupportsTelephony |
UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
UIDeviceSupportsBuiltInMicrophone |
UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsBuiltInSpeaker |
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
UIDeviceSupportsAccessibility |
UIDeviceSupportsVoiceOver |
UIDeviceSupportsVoiceControl |
UIDeviceSupportsPeerToPeer |
UIDeviceSupportsARMV7 |
UIDeviceSupportsBrightnessSensor |
UIDeviceSupportsEncodeAAC |
UIDeviceSupportsBluetooth |
UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
UIDeviceSupportsVolumeButtons |
UIDeviceSupportsEnhancedMultitouch
);
case UIDeviceiPhoneSimulator:
return
(// UIDeviceSupportsTelephony |
// UIDeviceSupportsSMS |
// UIDeviceSupportsStillCamera |
// UIDeviceSupportsAutofocusCamera |
// UIDeviceSupportsVideoCamera |
UIDeviceSupportsWifi |
// UIDeviceSupportsAccelerometer |
UIDeviceSupportsLocationServices |
// UIDeviceSupportsGPS |
// UIDeviceSupportsMagnetometer |
// UIDeviceSupportsBuiltInMicrophone |
// UIDeviceSupportsExternalMicrophone |
UIDeviceSupportsOPENGLES1_1 |
// UIDeviceSupportsOPENGLES2 |
UIDeviceSupportsAccessibility | // with limitations
UIDeviceSupportsVoiceOver | // with limitations
UIDeviceSupportsBuiltInSpeaker
// UIDeviceSupportsVibration |
// UIDeviceSupportsBuiltInProximitySensor |
// UIDeviceSupportsVoiceControl |
// UIDeviceSupportsPeerToPeer |
// UIDeviceSupportsARMV7 |
// UIDeviceSupportsBrightnessSensor |
// UIDeviceSupportsEncodeAAC |
// UIDeviceSupportsBluetooth |
// UIDeviceSupportsNike |
// UIDeviceSupportsPiezoClicker |
// UIDeviceSupportsVolumeButtons
);
default: return 0;
}
}
// Courtesy of Danny Sung <[email protected]>
- (BOOL) platformHasCapability:(NSUInteger)capability
{
if( ([self platformCapabilities] & capability) == capability )
return YES;
return NO;
}
- (NSArray *) capabilityArray
{
NSUInteger flags = [self platformCapabilities];
NSMutableArray *array = [NSMutableArray array];
if (flags & UIDeviceSupportsTelephony) [array addObject:@"Telephony"];
if (flags & UIDeviceSupportsSMS) [array addObject:@"SMS"];
if (flags & UIDeviceSupportsStillCamera) [array addObject:@"Still Camera"];
if (flags & UIDeviceSupportsAutofocusCamera) [array addObject:@"AutoFocus Camera"];
if (flags & UIDeviceSupportsVideoCamera) [array addObject:@"Video Camera"];
if (flags & UIDeviceSupportsWifi) [array addObject:@"WiFi"];
if (flags & UIDeviceSupportsAccelerometer) [array addObject:@"Accelerometer"];
if (flags & UIDeviceSupportsLocationServices) [array addObject:@"Location Services"];
if (flags & UIDeviceSupportsGPS) [array addObject:@"GPS"];
if (flags & UIDeviceSupportsMagnetometer) [array addObject:@"Magnetometer"];
if (flags & UIDeviceSupportsBuiltInMicrophone) [array addObject:@"Built-in Microphone"];
if (flags & UIDeviceSupportsExternalMicrophone) [array addObject:@"External Microphone Support"];
if (flags & UIDeviceSupportsOPENGLES1_1) [array addObject:@"OpenGL ES 1.1"];
if (flags & UIDeviceSupportsOPENGLES2) [array addObject:@"OpenGL ES 2.x"];
if (flags & UIDeviceSupportsBuiltInSpeaker) [array addObject:@"Built-in Speaker"];
if (flags & UIDeviceSupportsVibration) [array addObject:@"Vibration"];
if (flags & UIDeviceSupportsBuiltInProximitySensor) [array addObject:@"Proximity Sensor"];
if (flags & UIDeviceSupportsAccessibility) [array addObject:@"Accessibility"];
if (flags & UIDeviceSupportsVoiceOver) [array addObject:@"VoiceOver"];
if (flags & UIDeviceSupportsVoiceControl) [array addObject:@"Voice Control"];
if (flags & UIDeviceSupportsBrightnessSensor) [array addObject:@"Brightness Sensor"];
if (flags & UIDeviceSupportsPeerToPeer) [array addObject:@"Peer to Peer Bluetooth"];
if (flags & UIDeviceSupportsARMV7) [array addObject:@"The armv7 instruction set"];
if (flags & UIDeviceSupportsEncodeAAC) [array addObject:@"AAC Encoding"];
if (flags & UIDeviceSupportsBluetooth) [array addObject:@"Basic Bluetooth"];
if (flags & UIDeviceSupportsNike) [array addObject:@"Nike"];
if (flags & UIDeviceSupportsPiezoClicker) [array addObject:@"Piezo clicker"];
if (flags & UIDeviceSupportsVolumeButtons) [array addObject:@"Physical volume rocker"];
if (flags & UIDeviceSupportsEnhancedMultitouch) [array addObject:@"Enhanced Multitouch"];
return array;
}
#pragma mark MAC addy
// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
// Accidentally munged during previous update. Fixed thanks to mlamb.
- (NSString *) macaddress
{
int mib[6];
size_t len;
char *buf;
unsigned char *ptr;
struct if_msghdr *ifm;
struct sockaddr_dl *sdl;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
if ((mib[5] = if_nametoindex("en0")) == 0) {
printf("Error: if_nametoindex error\n");
return NULL;
}
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 1\n");
return NULL;
}
if ((buf = malloc(len)) == NULL) {
printf("Could not allocate memory. error!\n");
return NULL;
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
printf("Error: sysctl, take 2");
return NULL;
}
ifm = (struct if_msghdr *)buf;
sdl = (struct sockaddr_dl *)(ifm + 1);
ptr = (unsigned char *)LLADDR(sdl);
// NSString *outstring = [NSString stringWithFormat:@"%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
NSString *outstring = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
free(buf);
return [outstring uppercaseString];
}
- (NSString *) platformCode
{
switch ([self platformType])
{
case UIDevice1GiPhone: return @"M68";
case UIDevice3GiPhone: return @"N82";
case UIDevice3GSiPhone: return @"N88";
case UIDevice4GiPhone: return @"N89";
case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
case UIDevice1GiPod: return @"N45";
case UIDevice2GiPod: return @"N72";
case UIDevice3GiPod: return @"N18";
case UIDevice4GiPod: return @"N80";
case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
case UIDevice1GiPad: return @"K48";
case UIDevice1GiPad3G: return @"K48"; // placeholder
case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
default: return IPOD_FAMILY_UNKNOWN_DEVICE;
}
}
@end