iPhone 4 app on iPad GUI Messed up

Hi,

I have an app which i’m building for iPhone 3GS, iPhone 4/4s and iPhone 5. But i also want to run the app on the iPad which should be working fine. I have a script running which checks the device and starts te appropriate scene for each device which works fine. When a device is not recognized by the script it switches back to the iPhone 3GS version.

I changed a few lines of code so that when the script recognizes the iPad it switches to the iPhone 4 version but then the GUI is all messed up. Which is weird because when it switches back to the 3GS version on the iPad it works fine but the iPhone 3GS version looks way uglier on the iPad than the iPhone 4 version.

Here’s the script i’m running:

#pragma strict

static var deviceGeneration_3G : int = 1;
static var deviceGeneration_4G : int = 2;
static var deviceGeneration_5G : int = 3;

private var device : int;


function Start()
{
	//Application.targetFrameRate = 60.0f;
	QualitySettings.SetQualityLevel(6);
	device = getDeviceGeneration();
	switch(device)
	{
		case 1:		Application.LoadLevel("app480x320");
					break;
					
		case 2:		Application.LoadLevel("app960x640");
					break;
					
		case 3:		Application.LoadLevel("app1136X640");
					break;
	}
}


function getDeviceGeneration() : int
{

	/*
	iPhone			First generation device
	iPhone3G		Second generation
	iPhone3GS		Third generation
	iPodTouch1Gen	iPod Touch first generation
	iPodTouch2Gen	iPod Touch second generation
	iPodTouch3Gen	iPod Touch third generation
	All devices with a resolution of 480 X 320
	*/
	
	 if(iPhone.generation == iPhoneGeneration.iPhone 
			|| iPhone.generation == iPhoneGeneration.iPhone3G 
			|| iPhone.generation == iPhoneGeneration.iPhone3GS 
			|| iPhone.generation == iPhoneGeneration.iPodTouch1Gen 
			|| iPhone.generation == iPhoneGeneration.iPodTouch2Gen 
			|| iPhone.generation == iPhoneGeneration.iPodTouch3Gen
			|| ( Screen.width == 480  Screen.height == 320 )) 
	{
		return deviceGeneration_3G;
	}
     /*
    iPhone4         // Fourth generation 
    iPhone4set		// Fifth generation    
    iPodTouch4Gen   // iPod Touch, fourth generation
    All devices with a resolution of 960 x 640
    */
	else if(iPhone.generation == iPhoneGeneration.iPhone4 
				|| iPhone.generation == iPhoneGeneration.iPodTouch4Gen 
				|| iPhone.generation == iPhoneGeneration.iPhone4S
				|| ( Screen.width == 960  Screen.height == 640 ))
	{
		return deviceGeneration_4G;
	}
	
	else if(iPhone.generation == iPhoneGeneration.iPhone5
				|| iPhone.generation == iPhoneGeneration.iPodTouch5Gen
				|| (Screen.width == 1136  Screen.height == 640))
	{
		return deviceGeneration_5G;
	}
	else if(iPhone.generation == iPhoneGeneration.iPad1Gen
						|| iPhone.generation == iPhoneGeneration.iPad2Gen
						|| iPhone.generation == iPhoneGeneration.iPad3Gen
						|| iPhone.generation == iPhoneGeneration.iPadUnknown)
	{
		return deviceGeneration_4G;
	}

	//FALLBACK to 480x320
    else
    {
    	return deviceGeneration_3G;
    } 
}

Could you be more specific about how the GUI is messed up? What GUI are we talking about here, the built-in of Unity, NGUI or something else?

No i’m using iGUI. But the thing is, shouldnt the GUI be the same on iPad in the iPhone view without zooming it in or out? I mean that’s why you can so easily run iPhone apps on the iPad right? Or do only iPhone 3GS apps work on the iPad? I’m talking about an iPad 2 and / or iPad mini.

iPhone apps work (and are required to work) on iPad. I use the screen resolution to position my GUI instead of checking what specific device it is.
An iPhone4x app (960x640) will return as 960x640 on the iPad when using Screen.width/height if it’s an iPhone only app.

True so when my devicecheck script detects an iPad and switches to the iPhone 4 that should not mess up the GUI on the iPad when the GUI is perfect on the iPhone 4 right?

In theory, correct. Are you sure your devicecheck returns the correct device when launched on iPad ?

Yes i know for sure that it works because when i don’t add the whole iPad code it returns to 3GS and it works (but looks ugly) and when i add the iPad code it changes on the iPad to 4G versie bus the GUI is messed up.

I added some line of code:

else if(iPhone.generation == iPhoneGeneration.iPad1Gen
						|| iPhone.generation == iPhoneGeneration.iPad2Gen
						|| iPhone.generation == iPhoneGeneration.iPad3Gen
						|| iPhone.generation == iPhoneGeneration.iPadUnknown
						|| (Screen.width == 1024  Screen.height == 768)
						|| (Screen.width == 2048  Screen.height == 1536))
	{
		return deviceGeneration_4G;
	}

The resolution part is now added. I’ll test it now.

EDIT:

Still doesn’t work. Funny thing is when i activate retinepad (my ipad 2 is jailbroken) it works… but not all iPads are jailbroken so that’s not an option

Sounds like you might want to check if your Unity version is up to date so it covers the 2nd generation iPad2 (with the smaller cpu) too.

Also, do you check the orientation before ending in this code or enforce a specific landscape orientation?
I ask cause it might fail otherwise too.

That being said, you run on a jailbroken device, so chances are that its actually failing for this reason, that Unitys generation detection fails itself.

  • I’m running Unity3d 3.5.6 f4
  • I don’t check the orientation, i have autorotation on
  • My boss has an iPad mini on which it also doesn’t work and he didn’t jailbreak his device
  1. Autorotation would bad as that means that portrait could happen where it will be 768x1024 instead of 1024x768.
    But I guess you would realize this error when holding it the wrong way round in portrait instead so until you intend to allow others to use it it does not matter :slight_smile:

  2. What do the project settings look like for the iOS platform for the project especially on the target device, target resolution, arm and target platform front?

Thx for your reply! My settings:

  • Target Device → iPhone Only
  • Target Platform → Universal armv6 +armv7 (OpenGL ES 1.1 + 2.0
  • Target Resolution → Native
  • Accelerometer frequency → disables
  • Target IOS version 4.3
  • SDK Version → IOS Latest

you must set the target device to iphone ipad.

If you set it to iphone only it will never run as an ipad application. It will either run at the non retina resolution 480x320 + 2x mode (ipad, ipad2, ipadmini) or run at the retina resolution 960x640 + 2x mode (ipad3, ipad4).
You have no control over this nor even access to it, this is the iOS inbuilt ‘iPhone to iPad’ emulation.

This explains the messup you get as well.

The GUI is expected to scale to the screen aspect ratio when you use relative sizes (0-2). If you want them to appear exactly identical you need to do a lot more converting of sizes. The relative sizes are meant to make an element use a percentage of the screen instead of an actual amount.

Also: “Target Device → iPhone Only” is part of your problem.

Thx for your reply, all my GUI sizes are in relative sizes. And i want the app to be iPhone only. Shouldn’t IOS recognize it then as an iPhone app and use the compatability view?