Frequently Asked Questions

Updated on Sat, 2012-08-25 11:30

Frequent Asked Questions

The following is a collection of "gotchas" that have commonly affected developers using the Twitter.framework. If you do not see an answer to your question here, please head to the Mobile Development Discussion Forums and post your question there.

I'm receiving authentication errors when using TWRequest. What's going on?

Are you certain that there are accounts stored on the device in Settings.app? No, seriously: are you sure that there are accounts stored on the device? One of the most common errors that developers experience is that they are not checking for the existence of at least one account before calling -[TWRequest setAccount:], and thus the request is sent unauthenticated.

We recommend checking +[TWTweetComposeViewController canSendTweet:] before you perform any actions that may require authentication. Additionally, you can also check the size of the array returned via -[ACAccountStore accountsWithAccountType:].

Do TWRequest and TWTweetComposeViewController calls automatically wrap urls in statuses updates?

Yes. Please review the documentation at t.co Link Wrapper FAQ and POST statuses/update for more information.

Want to see this for yourself? You can verify this behavior on your own with the following code snippet:

  1. ACAccountStore *store = [[ACAccountStore alloc] init];
  2. ACAccountType *twitterType = 
  3. [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
  4.  
  5. [store requestAccessToAccountsWithType:twitterType 
  6.                  withCompletionHandler:^(BOOL granted, NSError *error) {
  7.  
  8.   NSArray *accounts = [store accountsWithAccountType:twitterType];
  9.   NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
  10.   NSDictionary *dict = 
  11.     [NSDictionary dictionaryWithObjectsAndKeys:
  12.       @"This is a test https://dev.twitter.com/discussions/4682", @"status", nil];
  13.  
  14.   TWRequest *request = [[TWRequest alloc] initWithURL:url 
  15.                                            parameters:dict 
  16.                                         requestMethod:TWRequestMethodPOST];
  17.  
  18.   //  Use the first account for simplicity
  19.   [request setAccount:[accounts objectAtIndex:0]];
  20.  
  21.   [request performRequestWithHandler:
  22.     ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
  23.       if (responseData) {
  24.         id data = [NSJSONSerialization JSONObjectWithData:responseData 
  25.                                                   options:NSJSONReadingMutableLeaves 
  26.                                                     error:nil];
  27.         //  Print out the response.  
  28.         //  You can verify that the "text" of the status is now t.co'd.
  29.         NSLog(@"%@", data);
  30.       }
  31.   }];     
  32. }];

Why is my application attributed as "from iOS" instead of "from <my application>" on twitter.com?

If your application is not yet live in the App Store:

The application making the requests must be launched in Apple's App Store in order for the attribution to display on twitter.com. Note that the iOS5 version of the application must be live, not just a previous version.

If your application is live in the App Store:

In the majority of cases, your app will automatically be attributed on twitter.com. Please verify these steps if you do not see attribution:

  1. Ensure that all the fields on your iOS App Store application record are filled out and valid (e.g. valid URLs in URL fields and so on).
  2. Application names on Twitter are shorter than iOS application names. Some long iOS app names will cause attribution not to show.
  3. Don't attach "on iOS" "on iPhone" or "on iPad" to your app name
  4. Don't conflict with an app name already existing and registered on dev.twitter.com.

If you have verified each of these points and you still don't have attribution, please post in the discussion forums for further support.

I'm seeing strange crashes when using ACAccounts with TWRequest. What is going on?

This is a common problem for developers who are not utilizing Automatic Reference Counting (ARC). The solution is to either use ARC in your code, or ensure that you hold onto the ACAccountStore that "owns" the ACAccount that you are using for as long as need the ACAccount. This is the same pattern that holds for such classes as ALAssetsLibrary. To quote the documentation, "The lifetimes of objects you get back from a library instance are tied to the lifetime of the library instance."