Create a "hosted" view of a preference bundle outside of Preferences.app, and in a dedicated application.
- Create new tweak using "iphone/application_modern" template
- In the app's delegate file add the following to the
-(void)applicationDidFinishLaunching:(UIApplication *)application;
method:
/* TweakApplicationDelegate.h */
@interface TweakApplicationDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *rootViewController;
@end
/* TweakApplicationDelegate.m */
@implementation TweakApplicationDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
NSBundle *bundle = [NSBundle bundleWithPath:@"/Library/PreferenceBundles/TweakPreferences.bundle"];
[bundle load];
if ([bundle isLoaded]) {
_rootViewController = [[UINavigationController alloc] initWithRootViewController:[bundle.principalClass new]];
} else {
UIViewController *preferencesController = [[UIViewController alloc] init];
_rootViewController = [[UINavigationController alloc] initWithRootViewController:preferencesController];
}
_window.rootViewController = _rootViewController;
[_window makeKeyAndVisible];
}
@end
/* Tweak.h */
@interface TweakPreferencesController: UIViewController
@end
/* Tweak.xm */
%hook SomeViewController
- (void)presentPreferencesController:(id)sender {
NSBundle *bundle = [NSBundle bundleWithPath:@"/Library/PreferenceBundles/TweakPreferences.bundle"];
[bundle load];
if ([bundle isLoaded]) {
TweakPreferencesController *rootController = [objc_getClass("TweakPreferencesController") new]; // Tweak preference bundle principal class
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
[self presentViewController:navigationController animated:YES completion:nil];
}
}
%end