2013-07-19 32 views
5

我一直在使用這段代碼發佈twitter。SLCOmposeviewcontroller微博分享提醒問題

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]; 
} 

如果用戶沒有設置Twitter帳戶,它將顯示具有設置和取消按鈕的警報。但它沒有在設備中顯示警報?請任何人幫助我。提前致謝 。

+0

但它沒有在設備中顯示警報?沒有得到這個你問什麼... :( –

+0

你確定你正在運行> ios 6.0在設備 –

+0

是abhilash我的設備的iOS是6.1.3 – Tendulkar

回答

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

+0

請檢查我的代碼夥計我寫了相同的代碼COmpletion處理程序是要知道張貼的結果。 – Tendulkar

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]; 
}} 
5

同樣的事情發生與Facebook共享。取消測試:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) 

如果用戶的Twitter賬戶是不是已經在iOS 6中成立,上述測試將評估爲false並沒有共享的代碼將被執行。

相反,如果您跳過檢查並嘗試呈現SLComposeViewController無論如何,iOS會提示用戶設置他們的Twitter帳戶。

+0

謝謝Desty !!! – yogs