简体   繁体   中英

Handling Multiple Twitter Accounts on SLRequest

In using SLRequest there are some great tutorials for Tweeting in an iOS app. However, most of them simply pull the last object from the Twitter accounts. Since there can be multiple Twitter accounts signed in on iOS Settings, is the developer required to give an option for which account to choose from before Tweeting, or just use the default?

You are not "required" to give the user an option, but it is recommended you do.

One option is to us an action sheet like so:

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Choose an Account" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    for (ACAccount *acct in _accounts) {
        [sheet addButtonWithTitle:acct.username];
    }
    sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];
    [sheet showInView:self.view];

This assumes you have already loaded the accounts into an array (I named mine _accounts), and rather than select the last object, use this code to display all of the accounts available.

Then in your UIActionsheet delegate method, check which action sheet button was pressed:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != actionSheet.cancelButtonIndex) {

        self.accountToUse = [_accounts objectAtIndex:buttonIndex];

    }
}

This will set the account based on what the user picked. This is boilerplate and may need to be changed a little depending on where you are accessing it, but it is for the most part what you need!

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM