Pleased to report that I’ve got basic facebook integration working for Android & (partially) for Windows Phone 8 (as originally posted here). However, I’m drawing a blank with iOS:
I’ve installed the Xamarin facebook SDK component (the Outercurve Foundation version), and got the basic sample up and running, proving that I can log in. However, I’m having difficulty translating this into a Monogame game as the sample is based within an app-style framework, so you have a UIWindow with a DialogViewController and a UINavigationController and elements and a whole load of stuff I don’t know anything about.
I’ve tried replicating some of this into my Monogame game AppDelegate class, but no joy in getting any kind of window so far - I’m guessing that either it’s hidden behind the game or (more likely) I’ve got it wrong.
So if anyone’s gotten Facebook working on iOS, any pointers of how to trigger the login process from a Monogame game would be extremely handy!
Once I’ve got all three platforms working, I’m going to see if I can refine the code to make a cross-platform wrapper, which I’ll then post details of on here.
You probably have to set the context to that window to be able to see it, the fastest way for you to solve the problem and for us to be able to help you is that you create an extremely simple project. Have it only clear the buffer in the draw method and put all the facebook relevant code in it.
Test the facebook functionality on that sample and then if it still doesn’t work post it here so that we can put our hands on the code ourselves. (if possible please create a testing facebook app id or make it clear what and where we need to add the relevant secret codes and app-ids).
This will also help other users that incur the same problem.
I’ve made a bit of progress since posting this and - got a UINavigationController with the required facebook login page in a WebView to display by grabbing the game’s UIViewController from the services in the AppDelegate, then having it call PresentViewController with my facebook UINavigationController as the view controller to be presented.
However, the latest snag is a real stumper! I want the player to be able to cancel the facebook login from this UINavigationController that contains the webview, and return to the game. For this purpose, I’ve added a “cancel” button on the right of the navigation.
The first time this is tapped, it works perfectly - the UINavigationController dismisses and control is returned to the game. However, if you then attempt to open the login UINavigationController again after this, a memory warning is displayed in Xamarin Studio’s application output, and the app crashes.
Now, I’m guessing that this is because at the moment, my facebook helper class is static and something’s leaking somewhere (although I’ve got no idea where yet). So I’m trying to re-write my facebook helper into an instantiated class, which I can create in my AppDelegate and inject into my Game1 equivalent - obviously the WindowsPhone and Android versions will need to do the same thing from their GamePage and Activity classes respectively.
If you’ve seen this error before and know anything about it, it would be extremely helpful if you could let me know! Alternatively, if I continue to see the same behaviour with an instantiated class running facebook for me, I’ll post up a bare-bones solution with the appropriate requirements set up for people to have a hack around.
Happy to hear you progressed that far… Unfortunately it sounds like an implementation dependent issue so i will be of not much use here… What is the method that actually crashes the game? I suppose you tried to do step by step debugging to identify the issue.
You have to keep in mind that memory management between native and managed often create strange behaviour. You should definitely keep an eye on what might be disposed by the garbage collection while it might still be needed via native code, and vice versa.
@Eversor: bit more progress last night, thanks to that pointer about GC in managed vs native! I switched from creating the UINavigationController in the constructor to recreating it every time it needed to be presented, and forced it to dispose following closing… and the memory warning crash I was getting appears to have stopped!
The downside is that it’s a little laggy as I can’t pre-load the WebView content - but it’s a small price to pay for no crashes!
Just as a point of interest, step-by-step debugging resulted in a different sequence of errors, which I guess makes sense in light of the whole native-managed issue. But things are looking a lot more hopeful now.
My pleasure to help ya I know the pain of debugging managed-native opengl-views problems.