Open iOS Application from Unity

Open iOS application from Unity

The other application needs to support that behaviour, by defining a custom url scheme.
The developer needs add an URL Type i.e. "awesomeapp" in Xcode under Targets > Info > URL Types, if he does not support it you can not open the app.

In your Unity app just call

Application.OpenURL("awesomeapp://").

see also this stackoverflow entry:
Launch an app from within another (iPhone)

UPDATE 1: how to find a custom URL scheme of 3rd party app

  1. Download the purchased app via iTunes on OSX
  2. Go to the [AppName].ipa file on your filesystem
  3. Rename it to a [AppName].zip so that you can extract it
  4. Go to "[AppName]/Payload/[AppName].app"
  5. Right click and select "Show Package Contents"
  6. Open the Info.plist in Xcode and look for the key URL types or in a text editor for CFBundleURLTypes.

UPDATE 2: iOS 9

For iOS 9 you must whitelist that application in the Info.plist of the Xcode Project:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>awesomeapp</string>
</array>

Open Settings application on Unity iOS

You need to write a tiny iOS plugin for that, here is more information about it: http://docs.unity3d.com/Manual/PluginsForIOS.html

And here is your solution, ask if something should be unclear.

Script/Example.cs

using UnityEngine;

public class Example
{
public void OpenSettings()
{
#if UNITY_IPHONE
string url = MyNativeBindings.GetSettingsURL();
Debug.Log("the settings url is:" + url);
Application.OpenURL(url);
#endif
}
}

Plugins/MyNativeBindings.cs

public class MyNativeBindings 
{
#if UNITY_IPHONE
[DllImport ("__Internal")]
public static extern string GetSettingsURL();

[DllImport ("__Internal")]
public static extern void OpenSettings();
#endif
}

Plugins/iOS/MyNativeBindings.mm

extern "C" {
// Helper method to create C string copy
char* MakeStringCopy (NSString* nsstring)
{
if (nsstring == NULL) {
return NULL;
}
// convert from NSString to char with utf8 encoding
const char* string = [nsstring cStringUsingEncoding:NSUTF8StringEncoding];
if (string == NULL) {
return NULL;
}

// create char copy with malloc and strcpy
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}

const char* GetSettingsURL () {
NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
return MakeStringCopy(url.absoluteString);
}

void OpenSettings () {
NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL: url];
}
}

Unload & quit Unity from an external iOS App

When using the "Unity as a Library" Feature to integrate Unity into your native iOS application you won't be able to fully terminate Unity and return to your native App.

As stated in the Unity Documentation on integrating Unity into native iOS applications you are able to call the method - (void)unloadApplication; on the UnityFramework instance to release most of the memory it occupies, but not all of it. You will be able to run Unity again after doing so.



Related Topics



Leave a reply



Submit