Basically you want to “deploy two different apps in a single binary”. In case you already have two apps that don't share class names (or other top level object names), that should be pretty simple.
You should run device specific code as soon as possible and that is in main.m
. Pass different app delegate class for iPhone and for iPad. The rest should work as normal and no classes from the other “device” should be used.
int main(int argc, char * argv[]) {
@autoreleasepool {
UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom];
Class appDelegateClass = Nil;
if (idiom == UIUserInterfaceIdiomPhone) {
appDelegateClass = [iPhoneAppDelegate class];
}
else if (idiom == UIUserInterfaceIdiomPad) {
appDelegateClass = [iPadAppDelegate class];
}
NSCAssert(appDelegateClass, @"Unexpected idiom! Maybe iWatch?");
return UIApplicationMain(argc, argv, nil, appDelegateClass));
}
}
You could also choose different split point, for example allocating different root view controller.
In case you want to share some code after all, you can just create universal superclasses, for example iPhoneAppDelegate
and iPadAppDelegate
can have superclass AppDelegate
that handles notifications or URL handling.