Twitter Post iOS6 'Cancel' button issue
Asked Answered
C

5

14

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


}
Colleencollege answered 27/9, 2012 at 8:49 Comment(3)
Have you tried setting the completionHandler before presenting the View Controller?Beyond
That did the job, thanks Alex.Colleencollege
Nice one, I've posted the comment as an answer (see below). Cheers!Beyond
C
18

If your using the mySLComposerSheet this works great...

[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
Colleencollege answered 29/9, 2012 at 8:12 Comment(8)
And then you need to remember to NOT do this for a Facebook SLComposeViewController, which auto-dismisses itself! rdar:12440972Phillip
Yeah, forgot to mention that.Colleencollege
@Steven, can you check if Apple has fixed this as of today? Quite recently they fixed a lot of rdars...Eddra
I've been trying to verify but no luck so far due to another issue.Phillip
Fixed in a recent SDK release.Phillip
You can't use mySLComposerSheet since this is happening inside the block code. use self instead of mySLComposerSheet. BTW, thanks for the hint :)Edith
Answering @Klaas, this issue still exists for twitter as of October, 2013 with iOS 7 SDK.Dire
This is needed both in ResultCancelled and on ResultDone for Twitter but not FacebookEmbank
B
9

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];
}
Bathilda answered 11/11, 2012 at 6:46 Comment(1)
Exactly the same. Did you send some bug report to Apple? Or do you have a better way to solve it?Sunda
G
7

Found the issue. It only happens when a completion handler is added to TWTweetComposeViewController. If added, make sure to call:

[self dismissModalViewControllerAnimated:YES];

Geopolitics answered 28/9, 2012 at 21:53 Comment(1)
Please use [self dismissViewControllerAnimated:YES completion:nil]; instead of [self dismissModalViewControllerAnimated:YES];Edith
A
3

Try this buddy

   [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                [self performSelector:@selector(showalert)];
                [mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
                break;
            case SLComposeViewControllerResultDone:
                [self performSelector:@selector(showalert1)];
                [mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];
                break;

            default:
                break;


        }
    }];
Afflictive answered 5/2, 2013 at 13:20 Comment(1)
dissmissViewControllerAnimated is required if you use Twitter, but not if you use Facebook - there it works without!Officiary
B
1

Posting comment above as an answer:

Have you tried setting the completionHandler before presenting the View Controller?

Beyond answered 27/9, 2012 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.