From iPhone Development Wiki
Jump to: navigation, search

SBIconModel is a singleton class embodying all of the logic behind home screen pages and the dock. As of iPhone OS 3.1, it also handles communicating with the Applications tab in iTunes 9.

This class is only a model. To control the icon lists, you should use the SBIconController singleton class.

Communication with iTunes 9's Applications tab

As of iTunes 9, Apple's Applications tab allows users to rearrange applications on their home screens. However, certain scenarios, such as modified dimensions on SBIconList or defining a new maximum amount of pages on SBIconModel, aren't expected by iTunes, and it then either completely scrambles your home screen's arrangement on every sync involving applications or simply crashes iTunes.

Communication with iTunes is handled by two methods on SBIconModel: exportState and importState:. exportState returns an array of all icon lists and dictionary representations of the icons inside them. This is what iTunes will use to display the icons in the Applications tab. Any installed applications that are missing from the array this returns (due to LibHide, or having too many icons for the max amount of icon lists) will be appended by iTunes itself. importState: is the method called when iTunes proposes a new home screen arrangement. Ignoring all propositions from iTunes is as simple as hooking this method and returning NO.

Runtime icon insertion

With a simple hook to SBIconModel's -loadAllIcons one can add icons to SpringBoard's homescreen. However, this requires subclassing SBIcon or one of its subclasses in the runtime.

@interface SBIcon : NSObject

@interface SBIconController : NSObject
+ (id)sharedInstance;
- (void)addNewIconToDesignatedLocation:(SBIcon *)icon animate:(BOOL)animate scrollToList:(BOOL)scrollToList saveIconState:(BOOL)saveIconState;

@interface SBIconModel : NSObject
- (void)addIcon:(SBIcon *)icon;

// Provided SBTestIcon is a runtime subclass of SBLeafIcon for example

static NSMutableArray *_icons = nil;

%hook SBIconModel

- (void)loadAllIcons {
	for (id icon in _icons) {
		[self addIcon:icon];
		[[%c(SBIconController) sharedInstance] addNewIconToDesignatedLocation:icon animate:YES scrollToList:NO saveIconState:YES]; 


%ctor {
	NSAutoreleasePool *pool = [NSAutoreleasePool new];


	NSString *testIdentifierBase = @"test-";
	_icons = [NSMutableArray new];
	for (int i = 0; i < 4; i++) {
		NSString *testIdentifier = [testIdentifierBase stringByAppendingFormat:@"%d", i];
		SBTestIcon *icon = [[%c(SBTestIcon) alloc] initWithTestIdentifier:testIdentifier];
		[_icons addObject:icon];
		[icon release];

	// Register with IconSupport.
	void *h = dlopen("/Library/MobileSubstrate/DynamicLibraries/IconSupport.dylib", RTLD_NOW);
	if (h) {
		[(ISIconSupport *)[objc_getClass("ISIconSupport") sharedInstance] forExtension:@"testicons"];
	[icons release];

	[pool release];


External links