Preguntas más o menos en el título, authPlayerWithCompletionHandler está en desuso, entonces, ¿cómo debo usar authenticateHandler?authPlayerWithCompletionHandler Obsoleto, entonces, ¿cómo debo usar authenticateHandler
Respuesta
setAuthenticateHandler es nuevo en IOS 6, authenticateWithCompletionHandler todavía debe ser utilizado en IOS 5 y por debajo.
Además, proporcionar un controlador de finalización para presentViewController: animado: finalización: no es realmente necesario ya que el controlador de finalización se llama justo después de que se muestra la vista del centro de juego, no cuando se completa.
aquí está mi solución:
NOTA - probado en iOS 4.3, iOS 5.1, iOS 6.0 simuladores solamente - no en el dispositivo real.
NOTA - esto supone que ha comprobado que la API de GameCenter está disponible.
- (void)checkLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (localPlayer.isAuthenticated)
{
/* Perform additional tasks for the authenticated player here */
}
else
{
/* Perform additional tasks for the non-authenticated player here */
}
}
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] \
compare:v options:NSNumericSearch] == NSOrderedAscending)
- (void)authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
{
// ios 5.x and below
[localPlayer authenticateWithCompletionHandler:^(NSError *error)
{
[self checkLocalPlayer];
}];
}
else
{
// ios 6.0 and above
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error && viewcontroller)
{
[[AppDelegate sharedDelegate].viewController
presentViewController:viewcontroller animated:YES completion:nil];
}
else
{
[self checkLocalPlayer];
}
})];
}
}
}
¡Funciona bien! Sin embargo, ¿cómo se deshace del indicador de advertencia del método obsoleto? – msgambel
Simplemente configure el objetivo de despliegue en, p. Ej. 5.0 o cualquiera que sea su objetivo: seleccione el proyecto (fila superior en el navegador del proyecto)> seleccione su aplicación en Destinos> Resumen> Destino de despliegue. –
Esto es lo que se me ocurrió, parece que funciona. Siéntete libre de editar si crees que me he perdido algo.
-(void)authenticatePlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error) {
[self presentViewController:viewcontroller animated:YES completion:^{
if (localPlayer.isAuthenticated)
{
// your code if authenticated
}
else {
// your code if not authenticated
}
}];
}
else {
// error handling code here
}
})];
}
Estoy usando este código para iOS 6 y superior. No hay errores de compilación y parece funcionar bien.
#pragma
#pragma mark - Player Authentication
-(void)autheticatePlayer
{
__weak typeof(self) weakSelf = self; // removes retain cycle error
_localPlayer = [GKLocalPlayer localPlayer]; // localPlayer is the public GKLocalPlayer
__weak GKLocalPlayer *weakPlayer = _localPlayer; // removes retain cycle error
weakPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
[weakSelf showAuthenticationDialogWhenReasonable:viewController];
}
else if (weakPlayer.isAuthenticated)
{
[weakSelf authenticatedPlayer:weakPlayer];
}
else
{
[weakSelf disableGameCenter];
}
};
}
-(void)showAuthenticationDialogWhenReasonable:(UIViewController *)controller
{
[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:controller animated:YES completion:nil];
}
-(void)authenticatedPlayer:(GKLocalPlayer *)player
{
player = _localPlayer;
}
-(void)disableGameCenter
{
}
- 1. stringWithCString obsoleto ... entonces, ¿qué uso con char * devuelto por sysctlbyname?
- 2. ¿Debo usar Fragmentos para obtener un LoaderManager?
- 3. Elemento "alinear" es obsoleto o no estándar: ¿qué debo usar en su lugar?
- 4. glEnableClientState obsoleto
- 5. ¿Cómo debo usar HTMLAgilityPack AppendNode?
- 6. ¿Cuándo debo usar adornos?
- 7. ¿LDAP está obsoleto?
- 8. HTML obsoleto frente a obsoleto
- 9. ¿Cómo debo usar AsynchronousServerSocketChannel para aceptar conexiones?
- 10. ¿Qué DB debo usar?
- 11. load() método obsoleto?
- 12. initWithContentsOfFile Obsoleto
- 13. ¿Debo usar Bootstrap?
- 14. ¿Cuántas actividades debo usar?
- 15. ¿Cómo marcar algo en Qt como obsoleto (obsoleto)?
- 16. ¿Debo usar variables globales?
- 17. dismissModalViewControllerAnimated obsoleto
- 18. File.toURL() obsoleto?
- 19. ¿Debo usar CouchDB o SimpleDB?
- 20. ¿Debo usar AppDomain.CurrentDomain.BaseDirectory o System.Environment.CurrentDirectory?
- 21. ¿Es seguro usar .getWidth en la pantalla aunque está obsoleto
- 22. ¿Debo usar eval() o call_user_func()?
- 23. debo usar RoutedEventHandler
- 24. ¿Cuándo debo usar cuaterniones?
- 25. ¿Debo usar jQuery.each()?
- 26. ¿Qué metainformaciones debo usar?
- 27. ¿Debo usar claves externas?
- 28. ¿Debo usar HttpRuntime.Cache?
- 29. ¿Debo usar siempre genéricos?
- 30. stringWithContentsOfFile Obsoleto
Lea los difif de la API. –