Redirect to Settings Screen for Twitter Login

2019-04-10 18:26发布

In Twitter ,if User has Logged In in the Twitter Account in Settings Screen It will allow to post.Or Else it will display a Alert as "No Twitter Accounts" with 2 Options "Settings" and "Cancel". If Cancel is Tapped it will close alert and reject post to twitter. And if Settings is Tapped it is not redirecting to Settings Screen. Also i used

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

But No Luck. As far as i checked all are saying as from iOS 5.1 it wont work.But i see some apps still redirecting to settings screen in iOS7. Is it possible to redirect in iOS7. Thanks in Advance. enter image description here

1条回答
在下西门庆
2楼-- · 2019-04-10 18:34

You can use below code in your login button's action:

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];
}
查看更多
登录 后发表回答