Skip to content
Newer
Older
100644 62 lines (50 sloc) 1.66 KB
b97295a Extracted capabilities into its own (non-App Store safe) category, wh…
Erica Sadun authored Sep 8, 2010
1 /*
2 Erica Sadun, http://ericasadun.com
3 iPhone Developer's Cookbook, 3.0 Edition
4 BSD License, Use at your own risk
5 */
6
7 #import "UIDevice-Capabilities.h"
8 #import <dlfcn.h>
9
10 /*
11
12 THIS CATEGORY IS NOT APP STORE SAFE AT THIS TIME. DO NOT USE IN PRODUCTION CODE.
13 YOU CAN, HOWEVER, USE THIS TO HELP BUILD YOUR OWN CUSTOM CODE TO PRE_COMPUTE CAPABILITIES.
14
15 */
16
17 #define GRAPHICS_SERVICES_PATH "/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices"
18
19 @implementation UIDevice (Capabilities)
20
21 - (BOOL) supportsCapability: (NSString *) capability
22 {
23 void *libHandle = dlopen(GRAPHICS_SERVICES_PATH, RTLD_LAZY);
24 int (*GSSystemHasCapability)(NSString *);
25 GSSystemHasCapability = dlsym(libHandle, "GSSystemHasCapability");
26 BOOL result = GSSystemHasCapability(capability);
27 dlclose(libHandle);
28 return result;
29 }
30
31 - (id) fetchCapability: (NSString *) capability
32 {
33 void *libHandle = dlopen(GRAPHICS_SERVICES_PATH, RTLD_LAZY);
34 int (*GSSystemCopyCapability)(NSString *);
35 GSSystemCopyCapability = dlsym(libHandle, "GSSystemCopyCapability");
36 id capabilityValue = (id) GSSystemCopyCapability(capability);
37 dlclose(libHandle);
38 return [capabilityValue autorelease];
39 }
40
41 - (void) scanCapabilities
42 {
43 printf("Device: %s\n", [[self fetchCapability: UIDeviceMarketingNameString] UTF8String]);
44 for (NSString *capability in CAPABILITY_STRINGS)
45 {
46 printf("%s: %s\n", [capability UTF8String], [self supportsCapability:capability] ? "Yes" : "No");
47 }
48 }
49
50 - (NSArray *) capabilityArray
51 {
52 NSMutableArray *array = [NSMutableArray array];
53 for (NSString *capability in CAPABILITY_STRINGS)
54 {
55 if ([self supportsCapability:capability])
56 [array addObject:capability];
57 }
58
59 return array;
60 }
61 @end
Something went wrong with that request. Please try again.