2013-01-21 45 views
0

兼容性如Twitter框架ios5.0加入我使用它的類TWTweetComposeViewControllerTwitter的登錄與ios5.0,5.1,6.0

if([TWTweetComposeViewController canSendTweet]) 
    { 
     NSLog(@"can send tweet"); 
    } 
    else{ 
     NSString *message = @"The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don't have a Twitter account associated with this device."; 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:message delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
    [alertView show]; 
    } 

在這一步,我需要顯示用戶的Twitter的登錄頁面。爲此,我很困惑,如果我應該重定向用戶到設置登錄到用戶?

,如果是這個代碼不工作

 NSURL *twitterURL = [NSURL URLWithString:@"prefs:root=TWITTER"]; 
    [[UIApplication sharedApplication] openURL:twitterURL]; 

而且我看過一些在那裏,這將不會在iOS6的工作。那麼,我應該怎麼做才能讓用戶登錄一會兒,而不是直接發送推文。現在我只想讓用戶登錄。

我也參考this question它是與ios6很好,但在那種情況下,我如何處理ios5.1?

任何幫助將不勝感激....

回答

2

我想通了下面條件編碼.. 我只拿到了這種方式。如果有人有其他方式,請告訴我。

if (SYSTEM_VERSION_LESS_THAN(@"6.0")) { 
     if(SYSTEM_VERSION_EQUAL_TO(@"5.0")) 
     { 
      NSURL *twitterURL = [NSURL URLWithString:@"prefs:root=TWITTER"]; 
      [[UIApplication sharedApplication] openURL:twitterURL]; 
     }else{ 
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No_Tw", nil) message:NSLocalizedString(@"No_TW_Ac", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Button_Ok", nil) otherButtonTitles:nil, nil]; 
      [alertView show]; 
     } 
    } 

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) { 
     SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 
     tweetSheet.view.hidden=TRUE; 

     [self presentViewController:tweetSheet animated:NO completion:^{ 
      [tweetSheet.view endEditing:YES]; 
     }]; 
    } 

如果iOS版是5.0,然後它會重定向到登錄Twitter的,否則它會顯示警告用戶去設置,並執行登錄。而對於iOS 6.0及更高版本的SLComposeViewController工作正常。