我想确定用户是否登录了 twitter,所以我可以提示他们发布推文,但前提是他们设置了 ios 和 twitter。另外,有没有办法用默认推文设置推特屏幕?
问问题
1255 次
2 回答
5
对于 iOS 5.x,您可以使用以下命令检查用户是否已登录 twitter:
[TWTweetComposeViewController canSendTweet]
至于显示带有默认消息的推文屏幕,您可以执行以下操作:
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:defaultMsg];
[self presentModalViewController:tweetSheet animated:YES];
您可以参考本教程了解更多信息。
编辑:对于iOS 6.0
及以上,使用:
// requires "Social.framework"
[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]
因此,一个示例用法可能是:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler = myBlock;
[controller setInitialText:@"#myHashTag"];
[controller addImage:myImage];
[self presentViewController:controller animated:YES completion:Nil];
}
else
{ /* Show error alert, etc*/ }
于 2013-02-15T16:12:15.720 回答
2
正如我在评论中所说,如果您使用的是 IOS 5 或更高版本,只需添加Twitter.framework
到您的项目中即可
#import <Twitter/Twitter.h>
//post tweets
- (IBAction)postTapped:(id)sender{
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:@" #hashtag"];
[self presentModalViewController:tweetSheet animated:YES];
}
else
{
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}
}
于 2013-02-15T16:16:16.780 回答