What Native Extensions Exist For NME?

Hi everyone! I'm working on a non-game app for iOS that I'd like to make using NME if possible, in case we want an Android version in the future, but I'm not sure if it's possible, as we want a lot of native iOS functionality that I'm not sure exists in N…

Viewing 1 to 9 (9 Total)
What Native Extensions Exist For NME?

Silvercaster893

Silvercaster893
Total Posts: 104
Joined: January 05, 2012

Hi everyone! I'm working on a non-game app for iOS that I'd like to make using NME if possible, in case we want an Android version in the future, but I'm not sure if it's possible, as we want a lot of native iOS functionality that I'm not sure exists in NME. The following are features that we need:

-Ability to send a phone number to the dialer
-Ability to access the contacts list and pick contacts to share with
-Ability to access the camera to take a picture and send that picture back to the app
-Possibly the ability to access the gallery to pick a picture to send back to the app
-Logging in to the app through Facebook or Twitter
-Sharing the app through Facebook or Twitter
-Ability to access GPS coordinates
-Possibly the ability to locate the user on a map and point out other things near them

I've been researching these things for a while now and haven't really been able to find anything definitive except for the GPS coordinates (not the map) The main problem is that this app has a pretty strict deadline of two months from now, which is a really short amount of time, as I'm sure you all know. So my question is does anyone know if there's any way to make these features work in NME now? Or is there any chance any of them are being worked on and will be done in the very near future?

Thanks,
Vince

Tags:
Posted on June 28, 2012 at 11:07 AM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: What Native Extensions Exist For NME?

I have a bunch of native extensions but they don't cover your exact cases. So far my stuff is specific to interacting with the filesystem, showing native UI elements overlaid, and utilities such as checking network connectivity.

I would be happy to help get the infrastructure in place for these. I have dealt with sending and receiving all sorts of data both synchronously and asynchronously between haxe and iOS (C++/Objective-C) and Android (C++/Java) including JSON and binary data. Would that be helpful?

Posted on June 28, 2012 at 5:10 PM

Silvercaster893

Silvercaster893
Total Posts: 104
Joined: January 05, 2012

Re: What Native Extensions Exist For NME?

Possibly. If there's a way that I can hook native iOS code up to my NME codebase that would get the job done. I know all the tasks I outlined are possible in native code so that should work, if there's a way for me to do that. Ideally it would be like, a set of functions or something I could call from NME and then simply implement in Objective C. Is that kind of thing possible? (I've never worked with native extensions or anything of the sort before so forgive my ignorance ^^; )

Posted on June 29, 2012 at 9:55 AM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: What Native Extensions Exist For NME?

Yup, once you get a basic system in place it's easy using the CFFI (an interface to call C++ functions directly from Haxe). The only part that can get complex is making sure the data is formatted as it goes between.

Joshua has a nice example here that sets up the basics:http://www.joshuagranick.com/blog/2011/10/03/sample-native-extensio...

Posted on June 29, 2012 at 10:00 AM

Silvercaster893

Silvercaster893
Total Posts: 104
Joined: January 05, 2012

Re: What Native Extensions Exist For NME?

Awesome! Can native iOS code be done in C++ though? I've only ever done it in Objective C...

Posted on June 29, 2012 at 10:11 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: What Native Extensions Exist For NME?

You can call Objective-C methods from C++ when you are compiling for iOS or OS X.

NME itself uses a C++ "ExternalInterface" file that manages the connections between your Haxe code and the native library methods. In many of the functions that are exposed to Haxe, many of them call methods that are defined in other files. Most of these files are C++ but some of them are Objective-C.

You might have something similar. In my "Test" extension, there is an ExternalInterface.cpp file as well as a Test.cpp file. You could have a Test.mm file instead and it could work for iPhone. It's very useful for calls that will only ever be executed for Apple platforms. That's a reason why I used C++ completely for the Test extension, was because I wanted it to cross-compile for each platform smiling

Posted on June 29, 2012 at 10:34 AM

crayfellow

crayfellow
Total Posts: 204
Joined: November 28, 2011

Re: What Native Extensions Exist For NME?

The .mm extension essentially means "Objective-C++" where C++ and Objective-C can coexist, this is the happy medium in my opinion. As you will see in Joshua's example, the C++/Objective-C++ classes can share a common header file to define a portable interface that is then implemented per target. You could do the same thing so you could use your extension for other platforms when/if that becomes useful.

I'll post some or all of mine if you want to see exactly how this can be done.

Posted on June 29, 2012 at 10:58 AM

Silvercaster893

Silvercaster893
Total Posts: 104
Joined: January 05, 2012

Re: What Native Extensions Exist For NME?

Cool! Yeah, crayfellow, if you could post your examples that would be great! Thank you guys! grin

Posted on June 29, 2012 at 1:47 PM

Silvercaster893

Silvercaster893
Total Posts: 104
Joined: January 05, 2012

Re: What Native Extensions Exist For NME?

As an update, I've managed to hook a couple native extensions for iOS into my project (the MailSender and LocationManager ones) and I think I get the idea about how to use those. However, I'm still rather lost on how I might go about making my own, if the functionality I was looking for in my initial post in this topic isn't available elsewhere. crayfellow, did you ever end up posting your examples anywhere?

Posted on July 30, 2012 at 2:55 PM