我一直在使用此代码进行推特发布。
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted....");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Success"
message:@"Posted Successfully"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
break;
}};
[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
[fbController setInitialText:@"Check out this article."];
//[fbController addURL:[NSURL URLWithString:@"http://soulwithmobiletechnology.blogspot.com/"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
如果用户未设置推特帐户,则显示具有设置和取消按钮的提醒。但它没有在设备中显示警报?有人可以帮我吗。提前谢谢。
答案 0 :(得分:5)
Facebook分享也是如此。删除测试:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
如果用户的Twitter帐户尚未在iOS 6中设置,则上述测试将评估为false,并且不会执行任何共享代码。
相反,如果您跳过检查并尝试呈现 SLComposeViewController ,iOS将提示用户设置他们的Twitter帐户。
答案 1 :(得分:1)
BOOL canCompose= [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter];
if (canCompose) {
SLComposeViewController *fbCompose=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[fbCompose setInitialText:addressLabel.text];
[self presentViewController:fbCompose animated:YES completion:nil];
}
尝试此代码而不是使用completionHandler
答案 2 :(得分:0)
请遵循本教程。这里打开警报。
http://www.appcoda.com/ios-programming-101-integrate-twitter-and-facebook-sharing-in-ios-6/
- (IBAction)postToTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"Great fun to learn iOS programming at appcoda.com!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}}