I have a native iOS code which is created in Xcode 5.1, Also I have one sample unity 3d ios project code.
I want to merge or integrate unity 3d ios code into my native ios code. How can I do that the same
Thanks In Advance
Check this out:
http://docs.unity3d.com/Manual/PluginsForIOS.html
Briefly:
Start first from simply one class let's say FooPlugin.cs in Unity3D which do the following:
[DllImport ("__Internal")]
private static extern float _FooPluginFunction();
which has public method:
public static void FooPluginFunction()
{
_FooPluginFunction(); // call the native extension
}
Then build XCode project and add some FooPlugin.m which implements this method:
void FooPluginFunction() {
// this is where native world is met
}
Related
I need help, i use application.OpenUrl for link in my app, (c# code), in unity, everythings work perfectly, but when i build it on my iphone, or ipad, the link didn't work..
Sorry for my english.
Here is the code :
public void onClick(Button btn)
{
string nombtn = btn.name;
if (infosNomUrl.ContainsKey(nombtn)) {
url = infosNomUrl[nombtn];
Application.OpenURL(url);
}
}
on iOS only the last link work.
But on Unity preview all links are working, is there a compatibility problem of OpenURL function on iOS ?
Thanks for the answer.
I'm trying to install Xamarin.Mobile in a PCL iOS project by NuGet and i'm gotting this error!
Could not install package 'xamstore-xamarin.mobile 0.7.1'. You are
trying to install this package into a project that targets
'Xamarin.iOS,Version=v1.0', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author.
This is my AppDelegate
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Xamarin.FormsMaps.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
My SDK version is 10.1.
Xamarin.Mobile is working fine in Android Project.
Any idea how to fix this ?
Use the Microsoft Resolution of problems.
Clean your Solution and Rebuild again.
The Xamarin.Mobile NuGet package is not compatible with a PCL, hence the error. This DLL is meant to be installed into an iOS/Android/Windows app project. There is no cross-platform API for PCL use.
You could use this with a Shared Library instead. Or, you'll need to work in each platform project.
Instead of add the package of Xamarin.Mobile with NuGet, you can try adding Xamarin.Mobile as a component.
Right click the Components folder:
Search and select Xamarin.Mobile on Xamarin Components window:
It might work!
After following this tutorial 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 / comment is greatly appreciated!!
PS. I'm using Unity 5.4.2 and Xcode 8.0. The Unity part uses the Google Cardboard SDK.
For using native plugins on iOS read the following info:
https://docs.unity3d.com/Manual/NativePlugins.html
https://docs.unity3d.com/Manual/PluginsForIOS.html
It's been a couple of months since this question, but in case anyone else runs into a similar issue, here's how I managed to resolve this.
I created a Cocoa touch framework
I created a public TestSDK swift class in that framework, it has public func makeSomething()
I created an iOS application
I built framework
I copied TestSDK to app and link TestSDK.framework
I added import TestSDK - no errors
I added let sdk = TestSDK() and get error:
Invalid use of '()' to call a value of non-function type
'module'
Solved it.
Framework build target device should be NOT "Generic iOS Device" but simulator or real device
I tried doing the same thing and it works fine. Just make sure you explicitly mark the class as public — default access control level is internal in Swift, e.g. only available inside the module.
I did export iOS Unity Project, and then i want to convert the project to iOS Framework Project. Because i want to make the project into SDK(.framework) for using the SDK in other normal app.
When it is built into framework project, Crash in UnityInitApplicationNoGraphics().
(crash occurred >>> il2cpp::vm:MetadataCache::Initialize())
Application project (include unity ios framework) is occurred in following function.
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
...
// it is occurred crash in following function. (the parameter is path of Application(.app))
UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);
...
}
It also is called UnityInitTrampoline(); and UnityParseCommandLine(argc, argv); of the framework in main.mm of Application Project (argv parameter is path of Application(.app)).
What is the meaning of UnityInitTrampoline(); and UnityParseCommandLine(argc, argv); functions?