2014-01-08 32 views
3

在Twitter中,如果用戶已在設置屏幕中的Twitter帳戶中登錄它將允許發佈。或者,它將顯示警報爲「沒有Twitter帳戶」與2個選項「設置」「取消」。如果Cancel被點擊,它將關閉提醒並拒絕發佈到twitter。如果Settings被點擊,它不會重定向到設置屏幕。 我還用重定向到Twitter登錄的設置屏幕

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

但沒有運氣。至於我檢查所有從iOS 5.1說它不會work.But我看到一些應用程序仍然重定向到設置屏幕在iOS7。是否可以在iOS7中重定向? 在此先感謝。 enter image description here

+1

U可以找到這個答案在這裏 - http://stackoverflow.com/questions/9667921/prompt-login-alert-with-twitter -framework-in-ios5 –

+0

Ok.so不可能重定向到設置屏幕? –

+0

這一切都是在iOS中爲你實現的,是的,設置URL鏈接已被刪除,但上述功能是在twitter框架中處理的。請在發佈問題之前閱讀關於文章的文檔 –

回答

5

您可以在您的登錄按鈕的操作使用下面的代碼:

if ([TWTweetComposeViewController canSendTweet]) 
{ 
    //yes user is logged in 
    accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

    // Request access from the user to use their Twitter accounts. 
    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) 
    { 
     // Did user allow us access? 
     if (granted == YES) 
     { 
      // Populate array with all available Twitter accounts 
      NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType]; 

      ACAccount *acct = [arrayOfAccounts objectAtIndex:0]; 

      // Set the cell text to the username of the twitter account 
      NSString *userID = [[acct valueForKey:@"properties"] valueForKey:@"user_id"]; 
      TwitterIdStr = [[NSString alloc] initWithString:userID]; 
      FbIdStr = [[NSString alloc] init]; 
      NSLog(@"%@",userID); 
      NSString *networkCheck = [[NSUserDefaults standardUserDefaults] valueForKey:@"isNetWorkAvailable"]; 
      if ([networkCheck isEqualToString:@"NotConnected"]) 
      { 
       // not connected 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        // Display/dismiss your alert 
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No network connection" message:@"You must be connected to the internet to proceed." delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil]; 
        [alert show]; 
       }); 

      } else 
      { 
       fNameStr = [[NSString alloc] init]; 
       lNameStr = [[NSString alloc] init]; 
       emailStr = [[NSString alloc] init]; 

       [self startProgressViewAgain]; 
      } 

     } 
    }]; 
} 
else 
{ 
    //show tweeet login prompt to user to login 
    TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init]; 

    //hide the tweet screen 
    viewController.view.hidden = YES; 

    //fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1 
    viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) { 
     if (result == TWTweetComposeViewControllerResultCancelled) { 
      [self dismissModalViewControllerAnimated:NO]; 
     } 
    }; 
    [self presentModalViewController:viewController animated:NO]; 

    //hide the keyboard 
    [viewController.view endEditing:YES]; 
} 
+0

謝謝阿修。這很有幫助,但我想要確定是否將屏幕重定向到設置將起作用。 –

+0

它會工作,但會讓你的應用程序在後臺進行。我在我的一些應用程序中成功使用了它。 – Ashutosh

+0

這是否有一個等效代碼用於phonegap?我目前正在使用phonegap與該應用程序是爲ios。我不能顯示上圖中顯示的警報。另外我無法找到一個方法,一旦按鈕被點擊,如何重定向到設置頁面, – decodingpanda