Thursday, January 24, 2013

Twitter for iOS6 without the modal view.

Hi,
I guess I got this one from some Stackoverflow question.
Link against Social.framework and accounts.framework.
 #import <Accounts/Accounts.h>  
 #import <Social/Social.h>  
 =========================================
 ACAccountStore *account = [[ACAccountStore alloc] init];  
 ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:    
           ACAccountTypeIdentifierTwitter];  
       
 [account requestAccessToAccountsWithType:accountType options:nil   
         completion:^(BOOL granted, NSError *error)  
 {  
    if (granted == YES)  
    {  
      NSArray *arrayOfAccounts = [account   
          accountsWithAccountType:accountType];  
   
      if ([arrayOfAccounts count] > 0)  
      {  
       ACAccount *twitterAccount = [arrayOfAccounts lastObject];  
   
       NSDictionary *message = @{@"status": @”My First Twitter post from iOS6”};  
         
       NSURL *requestURL = [NSURL   
        URLWithString:@"http://api.twitter.com/1/statuses/update.json"];  
   
       SLRequest *postRequest = [SLRequest   
         requestForServiceType:SLServiceTypeTwitter  
             requestMethod:SLRequestMethodPOST  
             URL:requestURL parameters:message];  
   
       postRequest.account = twitterAccount;  
   
       [postRequest performRequestWithHandler:^(NSData *responseData,   
             NSHTTPURLResponse *urlResponse, NSError *error)  
       {  
          NSLog(@"Twitter HTTP response: %i", [urlResponse   
             statusCode]);  
       }];  
      }  
    }  
 }];  
That's it, don't hesitate to comment, to share your knowledge and to correct me. 

0 comments:

Post a Comment