Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present Social View Controller Cocos2d

Im trying to use the social framework to present the "Post To Facebook" view controller from within Cocos2d. This is the code I would usually use in a storyboard app

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];
    }];
}

How would I get this up and running from within Cocos2d? currently it throws up a warning for the line

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

Thanks in advance

like image 723
Kyle Goslan Avatar asked Feb 20 '26 02:02

Kyle Goslan


1 Answers

In cocos2d 2.0 you can use [CCDirector sharedDirector] instead of self.

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

This works because CCDirector inherits from UIViewController.

like image 105
Ben Trengrove Avatar answered Feb 23 '26 16:02

Ben Trengrove