type open example facebook uiviewcontroller cocos2d-iphone social

facebook - type - open graph example



Presente controlador de vista social Cocos2d (2)

En cocos2d 2.0 puede usar [CCDirector sharedDirector] lugar de self .

[[CCDirector sharedDirector] presentViewController:facebook animated:YES completion:nil];

Esto funciona porque CCDirector hereda de UIViewController .

Estoy tratando de usar el marco social para presentar el controlador de vista "Publicar en Facebook" desde Cocos2d. Este es el código que normalmente usaría en una aplicación de guión gráfico

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { SLComposeViewController *facebook = [[SLComposeViewController alloc] init]; facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; [facebook setInitialText:[NSString stringWithFormat:@"text"]]; [self presentViewController:facebook animated:YES completion:nil]; [facebook setCompletionHandler:^(SLComposeViewControllerResult result) { NSString *output; switch (result) { case SLComposeViewControllerResultCancelled: output = @"Action Cancelled"; break; case SLComposeViewControllerResultDone: output = @"Posted"; NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; [ud setInteger:1 forKey:@"Shared"]; [ud synchronize]; default: break; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]; [alert show]; }]; }

¿Cómo podría obtener esto funcionando desde Cocos2d? actualmente arroja una advertencia para la línea

[self presentViewController:facebook animated:YES completion:nil];

Gracias por adelantado


Esto funciona para mí ...

- (void) facebookWithInitialText: (NSString *) text {

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { CCLOG( @"can post to Facebook"); AppController *app = (AppController*) [[UIApplication sharedApplication] delegate]; SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; [controller setInitialText:text]; // set initial text [controller addImage:[UIImage imageNamed:@"Icon-72.png"]]; //add an image [controller addURL:[NSURL URLWithString:@"http://www.cartoonsmart.com"]]; //add a URL to it [[app navController] presentViewController:controller animated:YES completion:nil ]; [controller setCompletionHandler:^(SLComposeViewControllerResult result){ [[app navController] dismissModalViewControllerAnimated:YES]; NSString *outout = [[NSString alloc] init]; switch (result) { case SLComposeViewControllerResultCancelled: outout = @"Post Cancled"; break; case SLComposeViewControllerResultDone: outout = @"Post Done"; default: break; } UIAlertView *myalertView = [[UIAlertView alloc]initWithTitle:@"Facebook" message:outout delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [myalertView show]; }]; } else { CCLOG( @"Facebook not accessible or one account not setup."); }

}