Skip to content

Commit

Permalink
UIKit shared artwork support for iOS 6
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Jun 25, 2012
1 parent ee85e86 commit ad09944
Showing 1 changed file with 60 additions and 39 deletions.
99 changes: 60 additions & 39 deletions Classes/ArtworkViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ - (NSArray *) sectionTitles;
@end


@interface NSObject (UISharedArtwork)
- (id) nameAtIndex:(NSUInteger)index;
@end


@implementation ArtworkViewController

@synthesize progressView = _progressView;
Expand Down Expand Up @@ -248,57 +253,73 @@ - (NSDictionary *) artwork
}
else
{
for(uint32_t i = 0; i < _dyld_image_count(); i++)
Class UISharedArtwork = NSClassFromString(@"UISharedArtwork");
id sharedArtwork = [[[UISharedArtwork alloc] performSelector:@selector(initWithName:inBundle:) withObject:@"Shared" withObject:[NSBundle bundleForClass:UISharedArtwork]] autorelease];
if (sharedArtwork)
{
if (strstr(_dyld_get_image_name(i), "UIKit.framework"))
NSMutableArray *sharedKeys = [NSMutableArray array];
for (NSUInteger i = 0; i < [sharedArtwork count]; i++)
{
struct mach_header* header = (struct mach_header*)_dyld_get_image_header(i);
NSMutableDictionary **__mappedImages = FindSymbol(header, "___mappedImages");
NSMutableDictionary **__images = FindSymbol(header, "___images");

NSString *deviceModel = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"iPad" : @"iPhone";
NSString *imageMapNamesSymbol = [NSString stringWithFormat:@"_ImageMapNames_Shared_%gx_%@", [[UIScreen mainScreen] scale], deviceModel];
BOOL isVersion5OrLater = [UIImage instancesRespondToSelector:@selector(CIImage)];
if (isVersion5OrLater)
imageMapNamesSymbol = [NSString stringWithFormat:@"_ImageMapNames_Shared_%gx", [[UIScreen mainScreen] scale]];
struct imageMapInfo **imageMapNames = FindSymbol(header, [imageMapNamesSymbol UTF8String]);

// Force loading all images (iOS 4 only)
if (imageMapNames)
NSString *name = [sharedArtwork nameAtIndex:i];
if (name && [[sharedArtwork imageNamed:name] scale] == [[UIScreen mainScreen] scale])
[sharedKeys addObject:name];
}
keys = sharedKeys;
}
else
{
for(uint32_t i = 0; i < _dyld_image_count(); i++)
{
if (strstr(_dyld_get_image_name(i), "UIKit.framework"))
{
// iOS 4.1
while (*imageMapNames)
struct mach_header* header = (struct mach_header*)_dyld_get_image_header(i);
NSMutableDictionary **__mappedImages = FindSymbol(header, "___mappedImages");
NSMutableDictionary **__images = FindSymbol(header, "___images");

NSString *deviceModel = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? @"iPad" : @"iPhone";
NSString *imageMapNamesSymbol = [NSString stringWithFormat:@"_ImageMapNames_Shared_%gx_%@", [[UIScreen mainScreen] scale], deviceModel];
BOOL isVersion5OrLater = [UIImage instancesRespondToSelector:@selector(CIImage)];
if (isVersion5OrLater)
imageMapNamesSymbol = [NSString stringWithFormat:@"_ImageMapNames_Shared_%gx", [[UIScreen mainScreen] scale]];
struct imageMapInfo **imageMapNames = FindSymbol(header, [imageMapNamesSymbol UTF8String]);

// Force loading all images (iOS 4 only)
if (imageMapNames)
{
struct imageMapInfo *imageInfo = *imageMapNames++;
NSString *imageName = [NSString stringWithUTF8String:imageInfo->name];
(void)[UIImage performSelector:@selector(kitImageNamed:) withObject:imageName];
// iOS 4.1
while (*imageMapNames)
{
struct imageMapInfo *imageInfo = *imageMapNames++;
NSString *imageName = [NSString stringWithUTF8String:imageInfo->name];
(void)[UIImage performSelector:@selector(kitImageNamed:) withObject:imageName];
}
}
}
else
{
// iOS 4.0
int *__sharedImageSets = FindSymbol(header, "___sharedImageSets");
if (__sharedImageSets)
else
{
NSString **sharedImageNames = (NSString**)(*(int*)(__sharedImageSets + 4));
NSUInteger sharedImageCount = (*(int*)(__sharedImageSets + 5));
if (sharedImageNames)
// iOS 4.0
int *__sharedImageSets = FindSymbol(header, "___sharedImageSets");
if (__sharedImageSets)
{
for (int i = 0; i < sharedImageCount; i++)
NSString **sharedImageNames = (NSString**)(*(int*)(__sharedImageSets + 4));
NSUInteger sharedImageCount = (*(int*)(__sharedImageSets + 5));
if (sharedImageNames)
{
NSString *imageName = sharedImageNames[i];
(void)[UIImage performSelector:@selector(kitImageNamed:) withObject:imageName];
for (int i = 0; i < sharedImageCount; i++)
{
NSString *imageName = sharedImageNames[i];
(void)[UIImage performSelector:@selector(kitImageNamed:) withObject:imageName];
}
}
}
}

if (__mappedImages)
keys = [*__mappedImages allKeys]; // iOS 3
else if (__images)
keys = [*__images allKeys]; // iOS 4

break;
}

if (__mappedImages)
keys = [*__mappedImages allKeys]; // iOS 3
else if (__images)
keys = [*__images allKeys]; // iOS 4

break;
}
}
}
Expand Down

0 comments on commit ad09944

Please sign in to comment.