i am new to unity.
my aim is to write native wrapper for existing ios sdk.
for a start, i have written sample ios sdk, with just few test methods.
code is written in swift:
https://pastebin.com/auqNutu7
and another file which expose swift functions so that they can matchup with something which unity understands.
https://pastebin.com/rvrSs2aY
and on unity side:
https://pastebin.com/zezmCmKb
i have few queries, which i am not able to figure out.
is this correct way to write:
private static extern void AwesomeSDK_initializeSDK(string name, string apiKey, Action completionHandler);
if you see swift side of code.
i have completion handler/closure in swift method
(https://pastebin.com/auqNutu7)
, how can i relate it to exposed function
(https://pastebin.com/rvrSs2aY)
in swift framework, and also how can i write in unity side
(https://pastebin.com/zezmCmKb).
Related
I'm new in Swift and I would like if someone could tell me how can I use SNMP++ lib (written in C++) in a simple iOS application written in Swift? how to import the lib and begin coding? Thank You.
In 2016, Dariusz Stojaczyk wrote C code to construct probes and deconstruct response of SNMP v1 messages hidden in a project focused on BER. That project contains the code necessary to take one or more SNMP OIDs and construct a full SNMP message, then take a response and decode it, but has no networking code to actually do this.
I took this code and added an ObjectiveC wrapper that can be used to use the existing code to construct a SNMPv1 message, send it to an endpoint using a Socket, and receive a response with a user settable timeout using a dispatch block.
This code is far simpler than any of the big libraries that offer additional services like walking, v2/v3, and traps. If all you want to do is read one or more OIDs, then you should appreciate this code.
Objective-C can be mixed with C++.
That's called Objective-C++ (.mm files)
So if you can get the code into those files, in theory you can create a bridging header to deal with linking your swift files: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
Swift 2.2 does not work with C++, and neither will Swift 3. So it's not coming any time soon which means you simply can't develop a Swift app with a C++ library.
However Objective-C works with C++, so although you don't have to write your entire app in Objective-C, any code that deals with a C++ library will have to be written in Objective-C (or in C...).
You can then link your Objective-C code to you Swift app with a bridging header.
I am trying to get MIDI input for my unity project (for IOS). Since there is no direct support for MIDI I am trying to write a native plugin myself.
I got a C console application working using CoreMidi API, but now I have no idea how to connect it with unity, since all the examples I can find for doing native iOS plugins for unity are using Objective C.
Maybe anybody can help me, thanks!
I wrote a tutorial about this which could be a good start: http://unreferencedinstance.com/tutorial_cpp_unity3d/
In short:
You need to define your methods as extern, tell complier to make them available from 'the outside' and call them in Unity like this:
[DllImport ("LowLevelPlugin")]
private static extern int[,] fillArray(int size);
I am currently starting an iOS project and I want to use Unity as the primary drive for the project. Currently when you export Unity as an exported project, I am only given Objective-C.
How do I make a Unity based project using primarily Swift?
This seems extremely complicated as Objective-C can develop in top level and most of Unity is involved with the top level, how can I use Swift in this project? I am planning on using most of the Unity in Objective C and most of the front end GUI on Swift.
After a good couple of days hammering at this, it is possible. The main pitfalls was of course how the linking and the compilation process that Objective-C and Swift have to interact in order to do so:
Create an AppDelegate in Swift, subclassing UnityAppController and utilizing startUnity instead of Application(..)
Bridge between Swift and ObjectiveC using Unity's generated main.mm and the bridging headers
Create an Objective-C wrapper whose sole responsibility is to communicate between the Swift project and the Unity project
As follows here: https://apollowprogrammingblog.wordpress.com/2015/08/17/how-the-heck-do-you-integrate-swift-and-unity/
UPDATE July 11th 2016: There is also another guide, which I have since started using for my app development moving forward: https://github.com/blitzagency/ios-unity5. This is a different approach and also largely more maintainable due to the easily configurable unity.xcconfig (To get through most of the project config headaches) strat used here
I would like to know if it is possible to have a Unity iOS plugin made from the sources (.h .m) that allows the instantation of classes and not only calling static methods; and guidance about how to proceed.
I have a java library that has been converted to C# and ObjectiveC with the idea of producing Android, Windows and iOS plugins for unity to later make a transparent layer that will be used in my scene scripts.
Calling Unity C# from native code:
UnitySendMessage("UnityFactory", "CreateObject", "Message");
The "UnityFactory" could be implemented as factory to create new object. The "Message" could be the payload for the new object in json format.
Calling native (.mm not .m because .mm is c/c++ compatible) from Unity:
You have to use a static method but only one.
extern "C" {
void NativeSendMessage("NativeFactory", "CreateObject", "Message");
}
Does the same as the UnitySendMessage...
If you need more flexibility then add more functions to the Factory. In my sample there is only a "CreateObject" but if you don't want to create an object you could add a RouteToObject function ( but of course you need a registry mechanism and the object id in the "Massage" json ).
iOS GUI overlay
I'am not sure if this is relevant to you too but you can overlay the unity-view with UIView's. You have to look for "unity application controller subclassing"
I have a app project using libgdx 1.2. I want to add Parse.com push notifications to its iOS and Android builds. No problems with the usual java interface that enables the core app to call into the native platform methods, but I have quite a few problems in understanding how to call Parse.com SDK methods from Java RoboVM code, e.g., assuming NativeMethods were my interface for native methods access, and IOSNatives my iOS RoboVM implementation:
public class IOSNatives implements NativeMethods
{
public void pushNotifications()
{
// how do I write the java code equivalent to this example?
// step 5 here: https://parse.com/tutorials/ios-push-notifications
}
}
I mean, step 5 here: and then I need some hints about steps 1-4 too...
I've already searched SO for similar questions, but the only one I could find is
Is there a way for push notifications in libGDX (Android and iOS projects)?
which doesn't really tell what I need.
In order to work with IOS sdk's written on Objective C, you must use bindings. Binding is wrapper which allows you to call objective C code from java. Fortunately you don't need to write your own binding fot parse, because here is existing one: RoboVM parse binding.
You can look at Sample.java for example of implementation.
You can get more info about bindings and how to add them to your project here