Question about writing a wrapper for an iOS lib

Previous topic - Next topic

Falstaff

Hello all, as I've written about in this post, I'm looking to leverage TestFlight's SDK in my GLB apps. To do this I understand I have to write some sort of wrapper.

The code I'd like to wrap looks like this:

Code (glbasic) Select

-(IBAction)launchFeedback {
    [TestFlight openFeedbackView];
}


I have a rough idea of what to do on the GLB side of things from various forum topics I've found, but I'm pretty lost on where to put this code in my XCode project. I suppose I get as far as creating a TestFlightwrapper.mm file next to my main.m file, but I'm not sure what the format is for that file.

Any ideas? Thanks!

Moebius

'(IBAction)'  just tells XCode's interface builder that it's a function it can use.  AFAIK just putting it in a c function should work - have you tried something like this?
Code (glbasic) Select
void _GLB_Launch_Feedback (void) {
    [TestFlight openFeedbackView];
}


and then in GLB:
Code (glbasic) Select
IMPORT "C" void GLB_Launch_Feedback()
......
GLB_Launch_Feedback()


Don't ask me why there's an underscore - I'm pretty much copying what trucidare did w/ the bluetooth wrapper...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

matchy

Quote from: Falstaff on 2012-Apr-11
...but I'm pretty lost on where to put this code in my XCode project. I suppose I get as far as creating a TestFlightwrapper.mm file next to my main.m file, but I'm not sure what the format is for that file.

Have you read the existing tutorials and installed wrappers already made? Once you have you should be able to easily replace the first to your custom call.

Kitty Hello

uh-oh!
The underscore is bad. Try:
extern "C" void GLB_Launch_Feedback()
{

}

Falstaff

Hm, well it compiles, but when I try to trigger that function my app crashes.. and I can't figure out why since apparently my old mac mini is now too old to update to the new xcode which is required to debug an ios 5.1 device :/

Well, guess it's time to buy a new mac. Maybe we'll see what the new macbook refresh will have in store.

Falstaff

Ok, so I was able to get Lion running in a VM, which means I can once again attach a debugger to my iphone :)

It looks like the test flight SDK function is indeed at least being called in my code, but it crashes with an odd error.

Here is the error:

"bool _WebTryThreadLock(bool), 0x393aae0: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now..."

From what google says, it looks like it's a result of a 'background thread' trying to access the 'main thread'.. why would that be the case? I'm guessing it's something to do with how glbasic is rendering or something? I guess Testflight's sdk is trying to open up a web page and this isn't playing well with GLB.. doh.

Any suggestions?

Kitty Hello

Oh no. GLB runs in a thread, yes.

DaCarSoft

Try searching about "performselectoronmainthread".

I had to use it in my wrappers.

:)
"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.

Falstaff

It works! Thanks so much!  :nw:

This is what I ended up with.. a single additional file I called "TestFlightGLBWrapper.mm", under the 'classes' folder, that contains:

Code (glbasic) Select

#import "TestFlight.h"

extern "C" void GLB_Launch_Feedback()
{
    [TestFlight performSelectorOnMainThread:@selector(openFeedbackView) withObject: nil waitUntilDone: YES];
}


and in my GLB project I have a file called "testflight.gbas" which has the following code:

Code (glbasic) Select

?IFDEF IPHONE
IMPORT "C" void GLB_Launch_Feedback()
?ELSE
FUNCTION GLB_Launch_Feedback:
ENDFUNCTION
?ENDIF


Now I can offer a "feedback" button that a beta tester can click on to submit feedback right from their device, and it should show up in testflight's web interface.

Cool :)

DaCarSoft

"Si quieres resultados distintos... no hagas siempre lo mismo" - Albert Einstein.