I need to login to my twitter from my iOS app. I am able to check if there are any accounts that are set up in the settings in the device. Once it is confirmed that there are no accounts configured in the device, i want to able to login to my twitter account and then add the account to my device. I had a little luck in implementing checking if there are any accounts set up in the device using ACAccountStore. But can someone please help in implementing the later part in iOS7?

有帮助吗?

解决方案

SLComposeViewController *sheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

SLComposeViewControllerCompletionHandler completionBlock = ^(SLComposeViewControllerResult result){
  [sheet dismissViewControllerAnimated:YES completion:Nil];
};
sheet.completionHandler = completionBlock;
sheet.view.hidden = YES;

[_mainViewController presentViewController:sheet animated:YES completion:nil];

其他提示

  - (IBAction)tweetTapped:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
    SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
    [tweetSheet setInitialText:@"Your Tweet Message! :)"];
    if (self.imageString)
    {
        [tweetSheet addImage:[UIImage imageNamed:self.imageString]];
    }

    if (self.urlString)
    {
        [tweetSheet addURL:[NSURL URLWithString:self.urlString]];
    }
    [self presentViewController:tweetSheet animated:YES completion:nil];
}
else
{
    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Sorry"
                              message:@"You can't tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup"
                              delegate:self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [alertView show];
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top