Twitter Post iOS6 'Cancel' button issue

2019-02-12 01:03发布

问题:

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


}

回答1:

If your using the mySLComposerSheet this works great...

[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[mySLComposerSheet dismissViewControllerAnimated:YES completion:nil];


回答2:

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


回答3:

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

[self dismissModalViewControllerAnimated:YES];



回答4:

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;


        }
    }];


回答5:

Posting comment above as an answer:

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