以下是我在iOS应用程序中使用SLComposeViewController生成推文时所面临的问题。
首先,这是我的代码:
- (IBAction)twitButtonHandler:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetController.completionHandler=nil;
[tweetController setInitialText:@"Hello this is a tweet."];
if (![tweetController addImage:[UIImage imageNamed:@"MyNicePicture.png"]]) {
NSLog(@"Unable to add the image!");
} else NSLog(@"Add the image OK!");
[self presentViewController:tweetController animated:YES completion:Nil];
} else {
// The device cannot send tweets.
NSLog(@"No Tweet possible!");
return;
}
}上面的代码运行良好,只是我从来没有在实际的tweet中看到过图片,尽管它总是显示消息"Add The image OK!“在调试器中。有人能看到代码中的错误吗?或者告诉我潜在的问题在哪里?
发布于 2014-02-02 17:53:30
我自己更深入地研究这个问题,让我发现:
[UIImage imageNamed:@"MyNicePicture.png"]返回的是nil。
从那时起,一切都解释清楚了,问题出在我获取UIImage对象的方式上,而不是我最初想到的SLComposeViewController和SLServiceTypeTwitter。
https://stackoverflow.com/questions/21508258
复制相似问题