Accounts Framework For Adding Twitter

Discussion in 'iOS Programming' started by newtoiphonesdk, Oct 23, 2011.

  1. newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    I am working on implementing simple Twitter integration. In my appdelegate didFinishLaunchingWithOptions I have:
    Code:
     ACAccountStore *store = [[ACAccountStore alloc] init];
        ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
        [store requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
            
            if (granted) {
                //access granted;
                
            }
        }];
        [store release];
    
    This will ask for access to twitter accounts, and it works well, but after watching the WWDC video, I am not certain how to add the option to go to Settings and add a Twitter account if none exists already. After I do all this, can I simply use the pain-free Twitter integration and it can easily Tweet?
     
  2. Sykte, Oct 23, 2011
    Last edited: Oct 23, 2011

    Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #2
    If all you need is basic/simple this should work for you. No need to access the accounts.

    Code:
        //create a new instance of tweetComposeViewController
        TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
        
        //set the initial Text
        [tweetSheet setInitialText:[NSString stringWithString:@"Whatever you want"];
    
         //then present it modal
        [self presentModalViewController:tweetSheet animated:YES];
    
    
    If you want to make sure they have an account associated with twitter under "Settings" you can check with the following.

    Code:
         if ([TWTweetComposeViewController canSendTweet]) {
    
         }
    
    Take a look at the TWTweetComposeViewController documentation, it's extremely straight forward, it doesn't require api keys or app setup. They will however need to setup an account, I do not know of a way of programmatically sending them to settings.
     
  3. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #3
    Thanks. Only reason I wanted to do account lookup was for ease of use so they could either connect it to their twitter account or make one at first launch of app. If anyone else knows programmatically how to detect they don't have account and send them back to settings as option, I'd appreciate it.
     

Share This Page