Friday, August 24, 2012

Working with Sina Weibo in iOS 6


In this tutorial i am going to explain how we can integrate the micro blog site Sina Weibo in iOS 6. we need to follow the same steps what we did in facebook integration. You can refer the previous facebook iOS tutorial  .
For integrating the Sina Webio, need to create a new method and we are going to name it as
-(IBAction)SinaWeibo:(id)sender;
next step we need to add a new UIButton to the xib and rename it as Sina Webio and wire it with the method what we created in the viewcontroller.h Now we will move to the implementation part of the method what we created in the header. I am not going to explain the step by step coded, because it is self explanatory and you can simply understand what is the code do.
-(IBAction)SinaWeibo:(id)sender{
 
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
 
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo];
 
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
 
ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType];
 
NSLog(@"%@, %@", account.username, account.description);
 
}];
 
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
 
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
 
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
 
if (result == SLComposeViewControllerResultCancelled) {
 
NSLog(@"Cancelled");
 
} else
 
{
 
NSLog(@"Done");
 
}
 
[controller dismissViewControllerAnimated:YES completion:Nil];
 
};
 
controller.completionHandler =myBlock;
 
[controller setInitialText:@"Test Post from mobile.safilsunny.com"];
 
[controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];
 
[controller addImage:[UIImage imageNamed:@"sw.png"]];
 
[self presentViewController:controller animated:YES completion:Nil];
 
}
 
else{
 
NSLog(@"UnAvailable");
 
}
 
}
You are done. Run the application and test it.

1 comment: