Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Post iOS6 'Cancel' button issue

I'm in the process of changing my app for iOS6 and iPhone use, I can't seem to figure out why when I post from Twitter using the new Social framework I have to press 'Cancel' twice to close, anybody else have this issue or a fix? Here is the code for the button.

- (IBAction)twitterPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
    mySLComposerSheet = [[SLComposeViewController alloc] init];
    mySLComposerSheet = [SLComposeViewController   composeViewControllerForServiceType:SLServiceTypeTwitter];
    [mySLComposerSheet setInitialText:[NSString stringWithFormat:@"This is my tweet, hello!",mySLComposerSheet.serviceType]];
    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
    NSLog(@"dfsdf");
    switch (result) {
        case SLComposeViewControllerResultCancelled:
            break;
        case SLComposeViewControllerResultDone:
            break;
        default:
            break;
    }
}];


}
like image 678
Nathan Cleary Avatar asked Sep 27 '12 08:09

Nathan Cleary


2 Answers

If your using the mySLComposerSheet this works great...

[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
like image 156
Nathan Cleary Avatar answered Oct 18 '22 19:10

Nathan Cleary


My experience with SLComposeViewController is that twitter and weibo controllers need to be dismissed manually while the facebook controller seems to be better behaved.

If I don't dismissViewControllerAnimated myself, tapping the "Send" button will send the tweet or weibo posting but I'll be left with what seems to be an invisible view over my own view. Thus I can no longer interact with my app.

I don't know why my app is working like this... Interestingly, the completionHandler for cancel gets called just once. The second tap dismisses the view controller.

+ (void) shareText:(NSString*)text image:(UIImage*)image social:(NSString*)service url:(NSString*)url
{
    SLComposeViewController*    controller = [SLComposeViewController composeViewControllerForServiceType:service];

    [controller setInitialText:text];
    [controller addImage:image];
    [controller addURL:[NSURL URLWithString:url]];

    controller.completionHandler = ^(SLComposeViewControllerResult result) {
        if( SLComposeViewControllerResultDone == result )
        {
            NSLog(@"rewards for share: %@!", service );
        }
        if( ![SLServiceTypeFacebook isEqualToString:service] )  // facebook behaves
            [[CBLAppDelegate instance].activeViewController dismissViewControllerAnimated:true completion:nil];
    };
    [[CBLAppDelegate instance].activeViewController presentViewController:controller animated:true completion:nil];
}
like image 28
AutomatonTec Avatar answered Oct 18 '22 19:10

AutomatonTec