Trying to get Game Center to work with SDL in iOS

Hi, I’ve read all the topics and searched and I can’t find a complete answer to this.
I know I have to set a callback with SDL_iPhoneSetAnimationCallback, this is fine.
I have already set my authentication code, no prob here.
What I’m having trouble with is presenting the viewController that I get from the authentication handler.

I’m trying to use this code I’ve seen posted here, but it doesn’t compile.

Code:

UIViewController * GetSDLViewController(SDL_Window * sdlWindow)
{
UIKit_GetWindowWMInfo
SDL_SysWMinfo systemWindowInfo; -> Problems with this struct!
SDL_VERSION(&systemWindowInfo.version);
if ( ! SDL_GetWindowWMInfo(sdlWindow, &systemWindowInfo))
{
// consider doing some kind of error handling here
NSLog(@“GetSDLViewController error”);
return nil;
}
UIWindow * appWindow = systemWindowInfo.info.uikit.window;
UIViewController * rootViewController = appWindow.rootViewController;
return rootViewController;
}

I’ve included SDL_syswm.h but compilation fails with “ARC forbids Objective-C objects in structs or unions”.
I’m not sure if Apple changed some settings in the compiler, and this is not accepted anymore.
My question is: how can I get the SDL view controller? I don’t want to change nothing from the SDL source files. I’ve already wasted hours trying to solve this…
Let me add that I’m new to Objective-C (and that sure ain’t helping me).
Thanks!

You can turn ARC (Automatic Reference Counting) off in your project
settings.

What are you trying to accomplish with this code?On Thu, Mar 6, 2014 at 4:48 AM, Limanima <jorge.raposo.lima at gmail.com>wrote:

Hi, I’ve read all the topics and searched and I can’t find a complete
answer to this.
I know I have to set a callback with SDL_iPhoneSetAnimationCallback, this
is fine.
I have already set my authentication code, no prob here.
What I’m having trouble with is presenting the viewController that I get
from the authentication handler.

I’m trying to use this code I’ve seen posted here, but it doesn’t compile.

Code:

UIViewController * GetSDLViewController(SDL_Window * sdlWindow)
{
UIKit_GetWindowWMInfo
SDL_SysWMinfo systemWindowInfo; -> Problems with this struct!
SDL_VERSION(&systemWindowInfo.version);
if ( ! SDL_GetWindowWMInfo(sdlWindow, &systemWindowInfo))
{
// consider doing some kind of error handling here
NSLog(@“GetSDLViewController error”);
return nil;
}
UIWindow * appWindow = systemWindowInfo.info.uikit.window;
UIViewController * rootViewController = appWindow.rootViewController;
return rootViewController;
}

I’ve included SDL_syswm.h but compilation fails with “ARC forbids
Objective-C objects in structs or unions”.
I’m not sure if Apple changed some settings in the compiler, and this is
not accepted anymore.
My question is: how can I get the SDL view controller? I don’t want to
change nothing from the SDL source files. I’ve already wasted hours trying
to solve this…
Let me add that I’m new to Objective-C (and that sure ain’t helping me).
Thanks!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768

AH! ARC is “Automatic Reference Counting”… In that case the error makes sense.

This is what I’m trying to do:
I want to display the authentication view.
Here is the code:

  • (void)authenticateLocalPlayer
    {
    if (!gameCenterAvailable)
    {
    NSLog(@“Game Center not available on device, can’t authenticate user.”);
    return;
    }

    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

    if (localPlayer.authenticated != NO)
    {
    NSLog(@“Player already authenticated.”);
    return;
    }

    if (SYSTEM_VERSION_LESS_THAN(@“6.0”))
    {
    // ios 5.x and below
    [localPlayer authenticateWithCompletionHandler:nil];
    }
    else
    {
    // ios 6.0 and above
    [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error)
    {
    if (!error && viewcontroller)
    {
    [?!?!sdlViewController?!?! presentViewController:viewcontroller animated:YES completion:nil];
    }
    })];
    }
    }

I need this “?!?!sdlViewController?!?!”.

Pallav Nawani wrote:

You can turn ARC (Automatic Reference Counting) off in your project settings.

One addition to this: ARC can also be turned off for individual files [via Xcode]. I’ve had luck moving an app’s SDL_SysWMinfo-using code into a separate file, one that doesn’t compile with ARC, then having the rest of the Objective C/C++ files use ARC (which most of Apple’s sample code uses, nowadays).

More details on turning off ARC on a per-file basis can be found at http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project

Cheers,
– David L.

DLudwig wrote:

Pallav Nawani wrote:

You can turn ARC (Automatic Reference Counting) off in your project settings.

One addition to this: ARC can also be turned off for individual files [via Xcode]. I’ve had luck moving an app’s SDL_SysWMinfo-using code into a separate file, one that doesn’t compile with ARC, then having the rest of the Objective C/C++ files use ARC (which most of Apple’s sample code uses, nowadays).

More details on turning off ARC on a per-file basis can be found at http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project

Cheers,
– David L.

It worked!
The game center window is popping up.
Thank’s everybody, consider this problem solved.