Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Haxe from iOS app – hxRunLibrary() error

Tags:

ios

haxe

nme

hxcpp

For a client I've developed an iOS + Android app using Cordova (PhoneGap) for the user interface. Now, as an update to this app, I'm am attempting to add a game that was written in Haxe. Originally the game was written for the Flash target, but I've updated it to work with the C++ targets for Android and iOS.

On Android it was easy to integrate this with the Cordova app using activities (the Haxe part runs as a separate activity), but I am having some trouble achieving a similar result on iOS.

So far I have tried to include all hxcpp generated code in my project (in the same way that NME sets up the XCode project when you do "nme build ios"), and I'm calling hxRunLibrary() from my code when I want the game to run.

The problem is that hxRunLibrary() seems to want to create its own UIApplication instance, which fails with the following error, since my main app is already running an instance:

*** Assertion failure in void UIApplicationInstantiateSingleton(Class)(), /SourceCache/UIKit_Sim/UIKit-2380.17/UIApplication.m:2037
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.'

I think it might have something to do with SDL, which Haxe uses for graphics. From what I understand SDL needs to run from the main function of the app, which created a conflict with Cocoa that also needs to run from the main function.

Is there any easy way around this? I've looked in the hxcpp sources, but been unable to find the UIApplication related code, or any entry code for SDL.

Perhaps someone could point me in the right direction. Thanks!

like image 437
Splashdust Avatar asked Apr 16 '13 21:04

Splashdust


2 Answers

Well ,I have googled some information about Haxe . what i understood is that The Haxe will prouduce a completed application for you .that mean it include the main Function . That's why the error is happend .

And you can simulate the problem by invoke UIApplicationMain Function twice .

In my opinion , you have to remove the code about UIApplicationMain from the souce code file produced by Haxe.

like image 169
user3571842 Avatar answered Oct 18 '22 20:10

user3571842


cordova has the ability to be integrated as part of a bigger application

ran into the same issue.

http://devgirl.org/2012/11/15/embed-cordovaphonegap-in-your-native-ios-app/ this article will help

you dont actually create a new project instead you embed it in a webview via the ios webview and cordova acts a subview.

like image 33
Dnaso Avatar answered Oct 18 '22 21:10

Dnaso