App Freezes after sending tweet
Asked Answered
P

1

7

Hi I have two UIButtons in an iOS app. One is to post to twitter the second is to post to Facebook. The facebook button works perfectly however the tweet is casing me some problems, the tweet sheet will open with the populated text, however it takes two taps of the cancel button to dismiss. If I tap on send the tweet will be sent and the sheet dismissed but my app freezes and becomes unresponsive. I have included both bits of code

- (IBAction)postTweet:(id)sender {

// if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]){

    myTweet = [[SLComposeViewController alloc]init];

    myTweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    NSString *tweetString = [[NSString alloc]initWithFormat:@"%@\n%@\nvia @ValuatorApp", pdOne.text, pdTwo.text];

    [myTweet setInitialText:tweetString];

    [myTweet addURL:[NSURL URLWithString:@"http://sjb007.me/TheValuator"]];

    [self presentViewController:myTweet animated:YES completion:nil];
//   }
[myTweet setCompletionHandler:^(SLComposeViewControllerResult result) {

    NSString *output = [[NSString alloc]init];

    switch (result) {
        case SLComposeViewControllerResultCancelled:
            output = @"Twitter Post Cancelled";
            break;
        case SLComposeViewControllerResultDone:
            output = @"Twitter post Succesful";
            break;
        default:
            break;
    }
    NSLog(@"%@",output);

}];
}

- (IBAction)postFacebook:(id)sender {

// if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){

    myTweet = [[SLComposeViewController alloc]init];

    myTweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

if (pd3 != 0) {
    NSString *facebookString = [[NSString alloc]initWithFormat:@"%@\n%@\n%@", pdOne.text,pdTwo.text, pdThree.text];
    [myTweet setInitialText:facebookString];

}
else if (pd3 == 0){
    NSString *facebookString = [[NSString alloc]initWithFormat:@"%@\n%@\n", pdOne.text,pdTwo.text];
    [myTweet setInitialText:facebookString];

}

// [myTweet addImage:[UIImage imageNamed:@"Photo Jun 02, 22 46 37.jpg"]];

[myTweet addURL:[NSURL URLWithString:@"http://sjb007.me/TheValuator"]];

 [self presentViewController:myTweet animated:YES completion:nil];
 //   }
[myTweet setCompletionHandler:^(SLComposeViewControllerResult result) {

    NSString *output = [[NSString alloc]init];

    switch (result) {
        case SLComposeViewControllerResultCancelled:
            output = @"Facebook Post Cancelled";
            break;
        case SLComposeViewControllerResultDone:
            output = @"Facebook post Succesful";
            break;
        default:
            break;
    }
    NSLog(@"%@",output);

}];
}
Pilotage answered 9/10, 2012 at 12:53 Comment(1)
Having the exact same issue, did you find a fix?Ceyx
S
18

You are presenting the ViewController "myTweet"

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

but there is no dismiss... statement in your completionHandler

[self dismissViewControllerAnimated:YES completion:nil];
Stapler answered 25/10, 2012 at 8:22 Comment(3)
putting the dismiss code in after the switch statement fixed this issue for me, however its strange that its not needed for Facebook...Ceyx
see the following post #12617990Pilotage
This is needed both in ResultCancelled and on ResultDone for Twitter but not FacebookRestivo

© 2022 - 2024 — McMap. All rights reserved.