Twitter Sheet Image未附加 - iOS

时间:2013-05-10 16:19:51

标签: ios objective-c twitter

即使我正在调整图像大小,但我仍然没有在推文表上获取图像。

  - (void)twitterButtonPressed {


    NSString *post=[[NSString alloc]initWithFormat:@"I've burned so far %d Calories today -  update from iPhone app Run Burn Calories!", self.userActivityTotalCount];
    NSURL *url=[NSURL URLWithString:@"www.cpl.uh.edu"];
    UIImage *iconImage=[UIImage imageNamed:@"male_small_0.png"];
    UIImage *iconImage2=[self imageWithImage:iconImage scaledToSize:CGSizeMake(73.0, 73.0)];
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *twitterSheet=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [twitterSheet setInitialText:post];
        [twitterSheet addURL:url];
        [twitterSheet addImage:iconImage2];
        [self presentViewController:twitterSheet animated:YES completion:nil];
        SLComposeViewControllerCompletionHandler completion=^(SLComposeViewControllerResult result){
            switch (result) {
                case SLComposeViewControllerResultDone:
                    NSLog(@"posted successfully!");
                    break;
                case SLComposeViewControllerResultCancelled:
                    NSLog(@" could not posted!");
                    break;

                default:
                    break;
            }
            [twitterSheet dismissViewControllerAnimated:YES completion:nil];

        };
        twitterSheet.completionHandler=completion;

    }
    else{
        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account set up" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }

}

-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;

}

1 个答案:

答案 0 :(得分:0)

看起来您的推文太长了,无法添加两个链接(图片在通过Twitter分享时添加为链接)。

理论上,URL应该只在消息(+空格)中消耗20个字符,因为应该自动缩短,但似乎iOS推文表不能以这种方式工作。通过一些实验,我发现当你想要添加图像和URL时,你可以在推文中最多包含71个字符。