forked from erica/uidevice-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIDevice-Capabilities.m
61 lines (50 loc) · 1.66 KB
/
UIDevice-Capabilities.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
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook, 3.0 Edition
BSD License, Use at your own risk
*/
#import "UIDevice-Capabilities.h"
#import <dlfcn.h>
/*
THIS CATEGORY IS NOT APP STORE SAFE AT THIS TIME. DO NOT USE IN PRODUCTION CODE.
YOU CAN, HOWEVER, USE THIS TO HELP BUILD YOUR OWN CUSTOM CODE TO PRE_COMPUTE CAPABILITIES.
*/
#define GRAPHICS_SERVICES_PATH "/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices"
@implementation UIDevice (Capabilities)
- (BOOL) supportsCapability: (NSString *) capability
{
void *libHandle = dlopen(GRAPHICS_SERVICES_PATH, RTLD_LAZY);
int (*GSSystemHasCapability)(NSString *);
GSSystemHasCapability = dlsym(libHandle, "GSSystemHasCapability");
BOOL result = GSSystemHasCapability(capability);
dlclose(libHandle);
return result;
}
- (id) fetchCapability: (NSString *) capability
{
void *libHandle = dlopen(GRAPHICS_SERVICES_PATH, RTLD_LAZY);
int (*GSSystemCopyCapability)(NSString *);
GSSystemCopyCapability = dlsym(libHandle, "GSSystemCopyCapability");
id capabilityValue = (id) GSSystemCopyCapability(capability);
dlclose(libHandle);
return [capabilityValue autorelease];
}
- (void) scanCapabilities
{
printf("Device: %s\n", [[self fetchCapability: UIDeviceMarketingNameString] UTF8String]);
for (NSString *capability in CAPABILITY_STRINGS)
{
printf("%s: %s\n", [capability UTF8String], [self supportsCapability:capability] ? "Yes" : "No");
}
}
- (NSArray *) capabilityArray
{
NSMutableArray *array = [NSMutableArray array];
for (NSString *capability in CAPABILITY_STRINGS)
{
if ([self supportsCapability:capability])
[array addObject:capability];
}
return array;
}
@end