- Home /
How to test if game is currently deployed on iOS?
I am currently working on an iPad/iPhone game, which I frequently deploy test builds to PC and Mac for testing purposes (my testers don't have iPads.) Is there any easy way to do a test in scripting to see if the game is currently running on an iOS device?
Currently I have to comment out all of my iPhone Input-specific lines when I want to make a PC/Mac build, or I get compile errors. I realize that I'll still get compile errors even with an if statement... Is there a way for me to check if the build target is iPhone, and if not ignore all of my iPhoneInput lines?
UPDATE To clarify based on the answer and link below, this is how you actually implement an compile exception based on the device you are currently deployed to. In this example I am creating an exception for the code that automatically flips the screen orientation on iPad:
void FixedUpdate() {
#if UNITY_IPHONE
// screen orientation
//Source: http://forum.unity3d.com/threads/45747-iPad-Rotation
if ((iPhoneInput.orientation == iPhoneOrientation.Portrait) && (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.Portrait))
{ iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Portrait; }
if ((iPhoneInput.orientation == iPhoneOrientation.PortraitUpsideDown) && (iPhoneSettings.screenOrientation != iPhoneScreenOrientation.PortraitUpsideDown))
{ iPhoneSettings.screenOrientation = iPhoneScreenOrientation.PortraitUpsideDown; }
#endif
}
Hopefully, that's clear - what you are doing is just wrapping the iOS-exclusive code with the #if UNITY_IPHONE statement and ending it with the #endif. When you go to compile on Mac or PC, that bit of code is completely ignored.
As an additional note, the editor DOES compile that code when you execute, but obviously, it is equipped to handle iOS-specific commands.
Answer by Jessy · Nov 02, 2010 at 03:25 AM
You're not going about it quite right.
http://unity3d.com/support/documentation/Manual/Platform%20Dependent%20Compilation.html
This did solve my problem. I've given an example in my question above that shows how I actually implemented this in my code.
Your answer
Follow this Question
Related Questions
What iOS device to use/purchase for testing. 2 Answers
free Android and IOS 1 Answer
Advertising Identifier declaration missing? Testflight external testers 0 Answers
mac virtualbox virtual machine not recognising usb device 0 Answers
Can I post a game? 2 Answers