【问题标题】:Twitter integration through SLComposeViewController in iPhone通过 iPhone 中的 SLComposeViewController 集成 Twitter
【发布时间】:2014-05-10 07:39:05
【问题描述】:

我正在使用 SLComposeViewController 在 twitter 上分享图片。如果我没有通过 iPhone 设置登录,我想显示警报视图。请任何机构提出建议。

【问题讨论】:

标签: ios twitter


【解决方案1】:

使用此代码:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
//show compose view
else
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Not available"
                                                  message:@"Twitter is not available."
                                                 delegate:nil
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];

[message show];

【讨论】:

    【解决方案2】:

    使用 ACAccountStore 和 ACAccount 您可以查看您是否登录过的天气。

    在此处参考示例代码:How to post on twitter by hiding SLComposeViewController *tweetSheettweet instance

    【讨论】:

      【解决方案3】:

      在.h文件中声明

      @property (strong, nonatomic) ACAccount *fbAccount;
      @property (strong, nonatomic) NSString *slService;
      @property (strong, nonatomic) ACAccountStore *accountStore;
      

      在.m文件中添加

      - (IBAction)TwittButtonPressed:(id)sender
      {
      if(!accountStore)
          accountStore = [[ACAccountStore alloc] init];
      
      ACAccountType *twitterAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
      
      // Request access to the Twitter account with the access info
      
      [self.accountStore requestAccessToAccountsWithType:twitterAccountType options:nil completion:^(BOOL granted, NSError *error) {
          if (granted) {
              // If access granted, then get the Twitter account info
              NSArray *accounts = [self.accountStore accountsWithAccountType:twitterAccountType];
              if (accounts.count>0) {
                  self.fbAccount=[accounts lastObject];
              //NSLog(@"Twitter account Details =%@",self.fbAccount);
              self.fbAccount=[accounts objectAtIndex:0];
              NSString *username1 = self.fbAccount.username;
                         NSUserDefaults   *defaults = [NSUserDefaults standardUserDefaults];
              [defaults setValue:username1 forKey:@"twitUserName"];
              [defaults synchronize];
              //NSLog(@"USer ID %@and Username%@",[defaults valueForKey:@"twitUserID"],[defaults valueForKey:@"twitUserName"]);
      
              self.slService = SLServiceTypeTwitter;
                 // NSLog(@"Show indicatoer############");
              [self performSelectorOnMainThread:@selector(sharingPostData:) withObject:_slService waitUntilDone:YES];
      
      
              }
              else{
                 // NSLog(@"Access not granted");
                  [self performSelectorOnMainThread:@selector(throwAlertWithTitle:) withObject:@"Account not found. Please setup your account in settings" waitUntilDone:NO];
              }
              //  [self sharingPostData:self.slService];
      
          } else {
             // NSLog(@"Access not granted");
              [self performSelectorOnMainThread:@selector(throwAlertWithTitle:) withObject:@"Account not found. Please setup your account in settings" waitUntilDone:NO];
          }
      }];      
      }
      
      -(void)throwAlertWithTitle:(NSString *)message{
      //remove DSActivity if any
      UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Notification" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
      [errorAlert show];
      errorAlert=nil;
      }
      
      -(void)sharingPostData:(NSString *)serviceType{
          if ([SLComposeViewController isAvailableForServiceType:serviceType])
          {
      
              SLComposeViewController *fvc = [SLComposeViewController composeViewControllerForServiceType:serviceType];
      
                  [fvc setInitialText:@"Share text here"];
                  [fvc addImage:backGroundImage.image];
                  [fvc addURL:[NSURL URLWithString:kAppituneslink]];
      
              [self presentViewController:fvc animated:YES completion:nil];
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-26
        • 1970-01-01
        • 1970-01-01
        • 2011-11-03
        • 1970-01-01
        • 2013-08-29
        • 2011-03-05
        相关资源
        最近更新 更多