I have recently published my application in the App Store and wanted to find an easy way to integrate the settings I have defined in the settings bundle directory.
After looking around, I finally included InAppSettingsKit (http://inappsettingskit.com/) which simulates the iPhone app-related settings in the application itself.
I wanted to give some insights on how to include such framework in a cocos2d application.
- First include the InAppSettingsKit directory in your application.
- In the specific cocos2d Scene you want the settings to appear do the following:
#import "IASKAppSettingsViewController.h"
@interface MyScene : Scene <IASKSettingsDelegate>
{
UIViewController *mainViewController;
....
}
@property(nonatomic, retain) UIViewController *mainViewController;
@synthesize mainViewController;
- (void) dealloc
{
....
[mainViewController release];
[super dealloc];
}
-(id) init
{
if (self=[super init])
{
UIViewController *_mainViewController = [[UIViewController alloc] init];
....
}
return self;
}
- (void)showSettingsModal
{
IASKAppSettingsViewController *appSettingsViewController = [[IASKAppSettingsViewController alloc] initWithNibName:@"IASKAppSettingsView" bundle:nil];
appSettingsViewController.delegate = self;
[appSettingsViewController setShowCreditsFooter:NO]; // Uncomment to not display InAppSettingsKit credits for creators.
// But we encourage you not to uncomment. Thank you!
appSettingsViewController.showDoneButton = YES;
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:appSettingsViewController];
[[[[Director sharedDirector] openGLView] window] addSubview:[[self mainViewController] view]];
[[self mainViewController] presentModalViewController:aNavController animated:YES];
[aNavController release];
}
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
[[self mainViewController] dismissModalViewControllerAnimated:YES];
[self performSelector:@selector(postDismissModal) withObject:nil afterDelay:.5];
// your code here to reconfigure the app for changed settings (if needed)
...
}
-(void)postDismissModal
{
[[[self mainViewController] view] removeFromSuperview];
}