MonoTouch.GameKit.GKLocalPlayer Class
Represents the authenticated local player.

See Also: GKLocalPlayer Members

Syntax

[MonoTouch.Foundation.Register("GKLocalPlayer", true)]
[MonoTouch.ObjCRuntime.Availability(Introduced=MonoTouch.ObjCRuntime.Platform.Mac_10_8)]
[MonoTouch.ObjCRuntime.Availability(Introduced=MonoTouch.ObjCRuntime.Platform.iOS_4_2)]
public class GKLocalPlayer : GKPlayer

Remarks

Represents the authenticated player for this device.

On iOS 6.0 and newer, to authenticate the user, set the GKLocalPlayer.AuthenticateHandler property to a delegate that takes both a UIViewController and an NSError parameters. This will trigger the authentication to take place. For older versions of iOS, you should call the GKLocalPlayer.Authenticate(GKNotificationHandler) method. The difference is that with iOS 6.0 your callback receives a UIViewController that you can present to your user, while the old API would present the API and invoke your callback on an arbitrary thread.

GameKit will call GKLocalPlayer.AuthenticateHandler on demand as your application transitions from background and foreground. It is important that you update any internal state when authenticated as the user might have logged off, and logged in with a different account.

c# Example

//
// This shows how to authenticate on both iOS 6.0 and older versions
//
if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
    //
    // iOS 6.0 and newer
    //
    GKLocalPlayer.LocalPlayer.AuthenticateHandler = (ui, error) => {

        // If ui is null, that means the user is already authenticated,
	// for example, if the user used Game Center directly to log in

	if (ui != null)
            current.PresentModalViewController (ui, true);
	else {
	    // Check if you are authenticated:
	    var authenticated = GKLocalPlayer.LocalPlayer.Authenticated;
	}
	Console.WriteLine ("Authentication result: {0}",err);
    };
} else {
    // Versions prior to iOS 6.0
    GKLocalPlayer.LocalPlayer.Authenticate ((err) => {
        Console.WriteLine ("Authentication result: {0}",err);
    });
};

Related content

Requirements

Namespace: MonoTouch.GameKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0