How to work with native APIs in Unity?

Is it possible to work with native non-game iOS APIs like HomeKit, MapKit, Core Motion, SiriKit, Contacts, etc? Do I need to use assets like iOS SDK Pro? Which ones do you recommend looking into?

For example, make voice-powered controls in a game with Siri? Or combine ARKit and HomeKit in one Unity application?

And what is the correct approach to make apps which rely on native APIs? Write and compile a separate app for iOS and a separate app for Andriod? Or use “if(ios){…} else if (android){…}” in one app?

Do NOT use iOS SDK Pro. It hasn’t been updated in over 2.5 years. It will not work, and you’ll get no support from them. Trust me, I was a paid user of this asset and regretted it immensely.

I ended up using prime31’s iOS plugins. They’re expensive as crap, but they work, they’re updated regularly, and he offers fast (if sarcastic and sometimes bordering on rude) support. Judging by his Twitter feed recently, though, it seems like he’s fallen out of love with Unity and is encouraging people to move to Unreal, so I’m not sure if you’d have the same experience today as I did a few years ago.

There are a number of iOS SDK plugins available on the Asset Store… much more than there were back when I needed one. Just read all the reviews and contact the developers with questions. The ones who get back to you with the responses you like should be the one you go with!

Anywhere in your game code that needs an API call, I’d have a function called from a controller that abstracts where it’s coming from. So let’s say, for IAP, instead of calling the iOS API directly, call your custom IAP controller, which then determines what platform you’re on and calls the correct API. So your main game code is totally platform agnostic, and only your custom API controllers will need updated when Google/Apple change the APIs or you want to support a new platform.

I did not do it this way for my game, and overhauling it to support Android was too much of a pain for me to bother with.

3 Likes

Schneider21, thank you very much for that answer!
Does a Unity app, bloated with different plugins for each Kit and platform, will be an overhead and lack performance/speed?

Let’s rephrase your question a bit:

Yes.

The most perfectly performing app is one that has no code and does nothing. Each thing you add to it starts tipping the scale, and your job as the developer is to not tip them to the point where the app degrades past an acceptable point.

The best advice I can give you at this stage is to not worry about that at all. Premature optimization will cripple you and cause you to never get anything done. Just make a game and add as much crap to it as you want to get it working. Once you start running into performance issues yourself… that’s when you begin worrying about optimizing.

3 Likes

That reminds me of two well-known principles of computer science.

  • Every nontrivial program has bugs.
  • Any program code can be simplified to smaller/shorter code that does the same thing.

Taken together, we can see that in theory, any computer program can be reduced to a single line of code that does not work.

3 Likes

You are correct. Although I would rephrase my question as:

PS Also, Schneider21, you are right: “Premature optimization is the root of all evil”, - Donald Knuth.

Yes. Mono is the framework Unity uses for handling scripting. Third party APIs and plugins are handled by it. Overhead will thus be the same overhead you’d add to any Mono or .NET based application. That said the difference is negligible. If the app suddenly has problems due to the overhead then it was already in a very bad state and about to have them anyway.

2 Likes