sharing Image in social sites (Facebook and Twitter)....first import social,facebook,twitter frameworks
/To share the final image on twitter
-(void)shareImageToTwitter
{
[self shareImage:savedImage withText:nil onSocialSite: SLServiceTypeTwitter];
}
//To share the final image on facebook
- (void)shareImageToFacebook
{
[self shareImage:savedImage withText:nil onSocialSite: SLServiceTypeFacebook];
}
here "savedImage " was sharing image
//Common method to share image on twitter & facebook
-(void)shareImage :(UIImage *)postImage withText :(NSString *)message onSocialSite :(NSString *const )socialSiteType
{
SLComposeViewController *socialSiteComposer=[ SLComposeViewController composeViewControllerForServic eType:socialSiteType];
if([SLComposeViewController isAvailableForServiceType: socialSiteType])
{
SLComposeViewControllerComplet ionHandler __block completionHandler=^( SLComposeViewControllerResult result){
[socialSiteComposer dismissViewControllerAnimated: YES completion:nil];
switch(result)
{
case SLComposeViewControllerResultC ancelled:
default:
{
NSLog(@"Cancelled.....");
}
break;
case SLComposeViewControllerResultD one:
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Posted successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
break;
}};
//Add content to post
[socialSiteComposer setInitialText: message];
NSData *data = UIImageJPEGRepresentation( postImage, 1.0);
[socialSiteComposer addImage:[UIImage imageWithData:data]];
[socialSiteComposer setCompletionHandler: completionHandler];
[self presentViewController: socialSiteComposer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"You can't post right now, make sure you have at least one account setup" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
/To share the final image on twitter
-(void)shareImageToTwitter
{
[self shareImage:savedImage withText:nil onSocialSite:
}
//To share the final image on facebook
- (void)shareImageToFacebook
{
[self shareImage:savedImage withText:nil onSocialSite:
}
here "savedImage " was sharing image
//Common method to share image on twitter & facebook
-(void)shareImage :(UIImage *)postImage withText :(NSString *)message onSocialSite :(NSString *const )socialSiteType
{
SLComposeViewController *socialSiteComposer=[
if([SLComposeViewController isAvailableForServiceType:
{
SLComposeViewControllerComplet
[socialSiteComposer dismissViewControllerAnimated:
switch(result)
{
case SLComposeViewControllerResultC
default:
{
NSLog(@"Cancelled.....");
}
break;
case SLComposeViewControllerResultD
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Posted successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
break;
}};
//Add content to post
[socialSiteComposer setInitialText: message];
NSData *data = UIImageJPEGRepresentation(
[socialSiteComposer addImage:[UIImage imageWithData:data]];
[socialSiteComposer setCompletionHandler:
[self presentViewController:
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"You can't post right now, make sure you have at least one account setup" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
No comments:
Post a Comment