# \#if UNITY\_IPHONE in javascript

**URL:** https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069
**Category:** Mobile
**Tags:** iOS
**Created:** [February 26, 2010, 10:34am UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069 "2010-02-26T10:34:19Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_96085372](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anon\_96085372](https://discussions.unity.com/u/anon_96085372)
#### Post date: [February 26, 2010, 10:34am UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/1 "2010-02-26T10:34:19Z")

</div>

Hi all!

Is there a way to get following code running in javascript?

```auto
#if UNITY_IPHONE
// iphone code
#else
// not iphone code
#endif

```

Thx for any help!

---

<div class="post-metadata">

### Author: ![sigsom](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sigsom/32/224636_2.png) [@sigsom](https://discussions.unity.com/u/sigsom)
#### Post date: [February 26, 2010, 12:06pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/2 "2010-02-26T12:06:10Z")

</div>

you could use if(Application.isEditor())

---

<div class="post-metadata">

### Author: ![mudloop](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mudloop](https://discussions.unity.com/u/mudloop)
#### Post date: [February 26, 2010, 12:32pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/3 "2010-02-26T12:32:50Z")

</div>

That’s not the same… The former will execute both on the device and in the editor, because they’re both “Unity iPhone”, while the latter will return false on the device and true in the editor.

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [February 26, 2010, 1:23pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/4 "2010-02-26T13:23:16Z")

</div>

there are no defines etc in JS  
this capability is strictly C# only

---

<div class="post-metadata">

### Author: ![anon\_96085372](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anon\_96085372](https://discussions.unity.com/u/anon_96085372)
#### Post date: [February 26, 2010, 2:02pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/5 "2010-02-26T14:02:27Z")

</div>

ok thx… bad news!

---

<div class="post-metadata">

### Author: ![mudloop](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@mudloop](https://discussions.unity.com/u/mudloop)
#### Post date: [February 26, 2010, 2:39pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/6 "2010-02-26T14:39:05Z")

</div>

Well, you could create a C# script with compiler directives that sets a boolean somewhere, and then you can access that from js (never tried both js and c# in one project so it probably won’t be that simple, but it should be doable).

---

<div class="post-metadata">

### Author: ![Jake\_Haas](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/jake_haas/32/476363_2.png) [@Jake\_Haas](https://discussions.unity.com/u/Jake_Haas)
#### Post date: [February 27, 2010, 10:05pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/7 "2010-02-27T22:05:04Z")

</div>

Would

```auto
if (Application.platform == RuntimePlatform.IPhonePlayer) {
// iPhone code
} else {
// Non iPhone code
}

```

work?

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [February 27, 2010, 10:10pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/8 "2010-02-27T22:10:33Z")

</div>

partially. the iphone define works on the player and the editor, while this check would only work on the iphone itself. yet its naturally much better than no check 🙂

---

<div class="post-metadata">

### Author: ![Joe\_ByDesign](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joe_bydesign/32/334821_2.png) [@Joe\_ByDesign](https://discussions.unity.com/u/Joe_ByDesign)
#### Post date: [September 15, 2010, 3:28pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/9 "2010-09-15T15:28:54Z")

</div>

Would like to see the OP’s issue included in .JS too.

my 0.02 😉

---

<div class="post-metadata">

### Author: ![KAKE](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kake/32/547761_2.png) [@KAKE](https://discussions.unity.com/u/KAKE)
#### Post date: [June 21, 2011, 5:42pm UTC](https://discussions.unity.com/t/if-unity-iphone-in-javascript/408069/10 "2011-06-21T17:42:32Z")

</div>

I came across this thread after finding [this](http://unity3d.com/support/documentation/Manual/Platform%20Dependent%20Compilation.html). It looks like it will work in JavaScript/UnityScript as well. I use it in a couple of places for mobile-specific things and it works great.
