How to start a project with both outputs iPhone & iPad? - iphone

Using the Pre Release Xcode 3.2.3 I get this as a Startup Project
(source: balexandre.com)
What should I chose / do to great a project that can have both iPad and iPhone as a target (not showing the iPhone App on iPad but a real iPad View)?
Thank you.
To avoid problems:
iPhone OS 3.1.3 is the latest release on iPhone
iPhone OS 3.2 is the latest release on iPad
My question does not infringe any agreements that me and Apple are bound to, as my question is regarding those already public Releases.
I just stated that on my Operating System I'm running the Xcode 3.2.3, that is all.

just found out a simple way:
alt text http://www.balexandre.com/temp/2010-04-17_1242.png
alt text http://www.balexandre.com/temp/2010-04-17_1241.png
Then, if you want to switch to XIB files per device, let's say, the MainView for iPhone is A and the MainView for iPad is B, in your AppDelegate you add this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// The default have the line below, let us comment it
//MainViewController *aController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
// Our main controller
MainViewController *aController = nil;
// Is this OS 3.2.0+ ?
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// It's an iPad, let's set the MainView to our MainView-iPad
aController = [[MainViewController alloc]
initWithNibName:#"MainView-iPad" bundle:nil];
else
// This is a 3.2.0+ but not an iPad (for future, when iPhone runs with same OS than iPad)
aController = [[MainViewController alloc]
initWithNibName:#"MainView" bundle:nil];
#else
// It's an iPhone (OS < 3.2.0)
aController = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
#endif
// Let's continue our default code
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
[window addSubview:[mainViewController view]];
[window makeKeyAndVisible];
return YES;
}

You can choose the Application Type as "Universal" .

Related

Multiple storyboard to manage the retina 4 and retina 3.5

Hi I'm trying to develop an app for iPhone 5 and iPhone 4/4s. I'm having trouble while using storyboard: I designed the storyboard for iPhone 4/4s, but when I try it on an iPhone 5 my GUI sucks...
I read on the internet that the easiest solution it's to use 2 storyboard: one for retina 4 and one for retina 3.5.
I wanted to ask you how I can call the different storyboard by code?
I created 2 storyboard file:
MainStoryboard.storyboard
MainStoryboardiPhone5.stroryboard
I found on internet that i should obtain the screen size of the device and load a different storyboard, but where I should do that? In Appdelegate.m in method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
To detect the size of the display I founded this code on the web:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (screenBounds.size.height == 568) {
NSLog(#"retina 4");
} else {
NSLog(#"retina 3.5");
}
return YES;
}
Now I should only find a way to invoke the different storyboard when I detect a retina 4 or a retina 3.5.
What I should do to invoke the correct storyboard?
Thank you
The iPhone 5's screen has a height of 568.
You can simply use this macro to check it its iPhone 5:
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
Then in your AppDelegate.m check for iPhone 5 and load that particular storyboard.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *mainStoryboard = nil;
if (IS_IPHONE_5) {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboardiPhone5" bundle:nil];
}
else {
mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
UPDATE:
Using the following macro
// Check if device is iPhone 5
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
// Get the storyboard name according to the device
#define GET_STORYBOARD_NAME(controllerName) IS_IPHONE_5 ? controllerName : [NSString stringWithFormat:#"%#-iPhone4",controllerName]
Now in your App Delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:GET_STORYBOARD_NAME(#"Main") bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
Note:
Always the iPhone4 storyboard name should be in this format
YourStoryboardName-iPhone4.storyboard
I know it's not really what you're asking, but it's really worth persevering with AutoLayout. Unless your views are so different (eg, using different graphics, etc), AutoLayout can cope with pretty much anything by way of rearranging stuff. It's tricky to start with as it doesn't really use static positions for your layout items, it works by you telling it your intentions for how to place things relative to everything else (superview, other items, etc). Check out some tutorials online (Ray Wenderlich's one is very good).

App crashes on [TestFlight takeOff:#""] in iOS 6.1.2

I have TestFlight SDK integrated into my iOS app. In iOS 6.1.2, sometimes the app crashes for the first-time app launch at TestFlight's -takeOff: method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
#ifdef TESTING
[TestFlight takeOff:#"MY_TESTFLIGHT_TEAM_TOKEN"];
[TestFlight setDeviceIdentifier:[[UIDevice currentDevice] uniqueIdentifier]];
#endif
// Override point for customization after application launch.
ProductListViewController *products=[[ProductListViewController alloc] initWithNibName:#"ProductListViewController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:products];
[products release];
navigationController.toolbarHidden = YES;
navigationController.navigationBarHidden = YES;
self.rootViewController = navigationController;
[self.window setRootViewController:rootViewController];
[navigationController release];
[self.window makeKeyAndVisible];
return YES;
}
Any help is greatly appreciated.
Thanks
This is a bug in the Testflight SDK. They ask you to update to the latest beta version.
See iOS exception EXC_GUARD
Could it be that you've forgotten to include the TestFlight SDK folder properly?

iPad simulator Interface rotation 90°

I am developing an app (a drum machine) for the iPad, I have a draft of the user interface.
The interface is OK in iOS 6.1 simulator:
But it's turned 90° in iOS 5.1 simulator:
This is how I call the View (after some help from stackoverflow members)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[XDrumViewController alloc] initWithNibName:#"XDrumViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
How to solve it?
It is likely that you are not defining
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
which is required on iOS < 6 to make autorotation work (see here). For a quick test, define:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
in your view controller. This will enable autorotation for landscape only (i.e, it will force your controller to landscape).

iPad simulator just shows black screen

I am developing an app in Xcode, I got it working and was putting some finishing touches.
Then I upgraded Xcode to the latest version, changed a bit the code for the Autorotate options (my app shouldn't autorotate) and fiddled with the supported rotation (landscape vs. portait).
Then suddenly my debug in iOs simulator just shows a black screen. The app builds fine but nothing is shown in the simulator....
And I can't really understand why...
Using Xcode 4.6
i don't have an ApplicationDidFinishLoading but I have this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES; }
Use Below Code instead in your ApplicationDidFinishLoading
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[YourFirstViewController alloc] initWithNibName:#"YourFirstViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
This may solve your problem. Please try it.
commenting the "shouldAutorotateToInterfaceOrientation" solved my problem.

how to do different coding for iphone and ipad in same .m file in universal app?

I have created app for iPhone. I have no of table views, image views, map views in my app. All data coming through web service. And I've given some static sizes for image and other views through coding. now, I need the same app for iPad. So i have to change coding of view sizes for Ipad. I need to do different coding for iPhone and iPad in the same .m file. Anyone pls suggest me how to do that!!!
Till i understood your question, i think this is what u need:
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// place the iphone code
}
else
{
// place the ipad code
}
and you can refer to this post : http://iphonedevelopment.blogspot.in/2010/04/converting-iphone-apps-to-universal.html
As you can see when you choose a universal app in the starting when you are taking a new project - in universal app Appdelegate.m file the apple provides the code for that.
see this -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
by same method you can distinguish the iPad and iPhone.
Thank You!!