سؤال

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