Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jmcorallo · Nov 03, 2016 at 12:46 PM · iosxcodenative pluginintegrationobjective-c

Issue with integration into native iOS app

Hello,

After following this tutorial (the-nerd.be) I managed to integrate a Unity app into a native iOS app. The problem I'm currently facing is when I try to go back from the Unity part to native iOS.

For Android I solved this by doing something like:

 public void ReturnToNative()
 {
 #if UNITY_ANDROID
     AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
     AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
     jo.Call ("goBack");
 #endif
 
 #if UNITY_IOS
     Application.Quit();
 #endif
 }

The native Java method "goBack" basically stops and then finishes an activity that contains the Unity part.

I know that for iOS the solution is not an Application.Quit(), I should use an iOS Plugin.

So my question is, what should this plugin do? How could I make it work?

I know how to create plugins, but I don't know what this particular plugin should contain.

Any help / hint / direction is greatly appreciated!!

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AD110 · May 25, 2017 at 08:20 AM 0
Share

please let me know if you found a solution

avatar image jmcorallo AD110 · May 25, 2017 at 01:20 PM 0
Share

I did, I'm not on my PC right now, but I'll upload the solution in an hour or so

avatar image AD110 · May 25, 2017 at 02:07 PM 0
Share

thanks jmcorallo, I'll be waiting.. :)

avatar image jmcorallo AD110 · May 25, 2017 at 03:41 PM 0
Share

I've already answered. It says it's waiting for a moderator to approve it...

avatar image AD110 · May 26, 2017 at 07:31 AM 0
Share

Don't know why they are taking so long. is it possible if you could send me the solution on ammadraza27@gmail.com

avatar image jmcorallo AD110 · May 26, 2017 at 07:49 PM 0
Share

there, it's ready ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by jmcorallo · May 26, 2017 at 04:16 PM

First of all, you can create a Unity view, but once it's started you cannot kill it (if you kill it you cannot reopen it again - this is where my app was crashing). So to go back to native, you have to hide the Unity view.

In my app specifically, I was integrating VR into a native app, so I had an intro scene that contained a button "Enter VR mode", which loaded the next scene. That being said, my quit was:

 public void QuitApp()
     {
         #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
         #endif
 
         #if UNITY_IOS && !UNITY_EDITOR
         LoadingScene.UnityPaused = true;
         SceneManager.LoadScene("LoadingScene");
         #endif
 
         #if UNITY_ANDROID && !UNITY_EDITOR
         AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
         AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
         jo.Call ("goBack");
         #endif
     }

Then in my Loading Scene I had:

     public static bool UnityPaused = false;
 
     #if UNITY_IOS && !UNITY_EDITOR
     [DllImport("__Internal")]
     private static extern void UnityRequestHide_MyPlugin();
     #endif
 
     void Start ()
     {
         #if UNITY_IOS && !UNITY_EDITOR
         if (LoadingScene.UnityPaused)
         {
             // if UnityPaused is true, Unity should go on background
             Debug.Log("Going back to native");
             UnityRequestHide_MyPlugin();
         }
         #endif
     }

In addition, inside Plugins/iOS, I added the following code (note, I didn't create a new plugin. Instead, I just added this method inside the existing CardboardAppController.mm that I already had imported with the GVR SDK. If you don't have any existing plugin or wish to create one, read the docs):

 void UnityRequestHide_MyPlugin() {
   if (GetAppController().quitHandler)
     GetAppController().quitHandler();
 }

If you followed the same tutorial for integration into native iOS, you'll have to make the following changes in the exported XCode project.

Inside UnityAppController.h, replace:

 inline UnityAppController* GetAppController()
 {
     return (UnityAppController*)[UIApplication sharedApplication].delegate;
 }

with:

 #import "AppDelegate.h"
 
 inline UnityAppController* GetAppController()
 {
     AppDelegate *delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
     return [delegate unityController];
 }

And inside UnityAppController.mm, find this method:

 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

And add this at the beginning:

 _quitHandler = ^{
 [[NSNotificationCenter defaultCenter] postNotificationName:hideVR object:nil];
 };

I hope this helps/guides any one who's running into similar issues.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image juliens137 · Oct 24, 2019 at 02:12 AM 0
Share

Hi, Thank you for this. Just wondering what the "hideVR" refers to in the last part of your post. Is that a variable you defined elsewhere?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unobtrusively extending AppController delegates. Possible? 2 Answers

iOS location permission plugin build fails 0 Answers

Execute native ios code in unity 1 Answer

Unity iOS how can I see my classes in xCode converted in obj-c 0 Answers

Native Gallery "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges