Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 naskardebadri · Jul 07, 2021 at 12:04 PM · iosnative pluginframework

How to Interact With native iOS framework in podspec github repository?

Another developer has created a native iOS framework for me to add to my Unity3D project, however, I do not know how to interact with it.

All I received was a cocoapod (.podspec). I have looked through tutorials and forums about this, and it seems that I require more files (.mm) but I am confused on who produces these files or how to obtain these files. This is the tutorial I am following: https://medium.com/voodoo-engineering/bringing-native-ios-frameworks-into-unity-games-by-hacking-ios-methods-2c656d18cf9b

I also have been trying to follow these instructions too: https://docs.unity3d.com/560/Documentation/Manual/PluginsForIOS.html

I am stuck because I am not sure if I have to create a C++ file to sit in the middle of the native framework and Unity3D to communicate with each other? cocoapod <-- C++ (.mm) file --> Unity3D Can this be generated or automated somehow? I could use some help with a step-by-step guide about this. I'm confused on the bridging part. Thanks in advanced!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by unity_SndF7xzWLSMUWQ · Jul 07, 2021 at 04:33 PM

I actually have been looking for the answer to this same question recently. There isn't very much documentation on this. Community is basically our best shot at demystifying technical issues. Has anyone else done this before?

I think I have a general idea of how it works, but I don't want to lead you down the wrong road since I have not actually done it myself. But here is my general understanding of it.

There is no way to communicate between Unity and XCode directly. So you have to create a bridge, like you mentioned. This bridge requires coding on both ends.

From the documentation link you posted (you are on the right track)

Unity iOS supports automated plugin integration in a limited way. All files with extensions .a,.m,.mm,.c,.cpp located in the Assets/Plugins/iOS folder will be merged into the generated Xcode project automatically. However, merging is done by symlinking files from Assets/Plugins/iOS to the final destination, which might affect some workflows. The.h files are not included in the Xcode project tree, but they appear on the destination file system, thus allowing compilation of .m/.mm/.c/.cpp files.

So, you need to create a UnityIOSBridge.m and place that class to the path "Assets/Plugins/iOS". Unity needs the plugins to be c-named, so it is a good practice to wrap up the methods which need to be called from Unity inside extern "C". But there is no hard and fast rule, you can create .m class and write your c-named methods just outside the implementation part and you can call them from Unity. The only constraint is that you can not call these methods if you are building your app on a simulator, as Unity iOS plugins only works on devices (as far as I know).

UnityIOSBridge.m class should look like as follows:

 #
 import "UnityIOSBridge.h"
 void messageFromUnity(char * message) {
  NSString * messageFromUnity = [NSString stringWithUTF8String: message];
  NSLog(@ "%@", messageFromUnity);
 }
 @implementation UnityIOSBridge
 @end


To call the above method from Unity, we have to write a Unity script, so let’s create the file UnityIOSBridge.cs.

 using UnityEngine;
 using System.Collections;
 using System;
 //This is needed to import iOS functions
 using System.Runtime.InteropServices;
 public class UnityIOSBridge: MonoBehaviour {
  /*
   * Provide function decalaration of the functions defined in iOS
   * and need to be called here.
   */
  [System.Runtime.InteropServices.DllImport("__Internal")]
  extern static public void messageFromUnity(string message);
  //Sends message to iOS
  static void SendMessageToIOS() {
   messageFromUnity("Hello iOS!");
  }
 }

But with this you require access to binary files. Because you received a cocoapod, there are more steps than what I outlined. I am trying to figure those out.

But here are my thoughts about the cocoapod. The files you need, such as the .h and .m files are automatically generated by the cocoapod when you import the library or framework. These are Objective-C files. What does your podfile look like in Unity after you import? You may have all that you need. Rename the .m file to .mm, and that will get you to the start of my post. Again, I have not done this myself, I am just guessing :-).

And as a reference, I have been looking at this article to learn (mostly): https://www.agnosticdev.com/blog-entry/swift/integrating-unity-and-vuforia-ios-swift-project

Comment
Add comment · Show 2 · 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 datnasty2_0 · Jul 07, 2021 at 06:01 PM 1
Share

I also had this problem, so thanks for making this and I will read these articles to further expand my knowledge.

avatar image naskardebadri · Jul 08, 2021 at 08:28 AM 0
Share

Thanks for taking the time to look into this. I would like to inform that what I received was a Podspec github repository containing iOS native framework. It is written using Swift Dynamic Library. I find no .m or .mm files inside this repository. I'm adding this podspec github repository as a dependency using the External Dependency Manager. Here in the iOS Resolver Usage section you can find the format to add the dependency. Also the same is stated in the Unity part of Step 2 of the Medium article that I had posted in my actual question. Now I don't know how to proceed from here onwards.

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

151 People are following this question.

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

Related Questions

Custom swift framework in Unity iOS game 0 Answers

iOS Simulator build for Facebook Review 2 Answers

EXC_BAD_ACCESS on PreparePresentRenderingSurface (iOS Build) 0 Answers

How do I get the Metal device for IOS within a native plugin? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers


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