Sunday, October 7, 2012

iOS 6 : Add Social Networking with Social Framework

Another Quick and easy Post for everyone who quickly wants to implement a social sharing solution.
Essentially, all you have to do is calling the UIActivityController. 
Sure, you don't always want to show all sharing options but the out-of-the-box solution is fairly good and should suffice for a lot of Projects.

Assuming you have a Button in your View and a Touch Event such as TouchInsideOut is hooked-up to a receiver function, following code is all you need :

NSArray* shareStuff = @[@"Cool stuff to share",[UIImage imageNamed:@"coolimage.png"]];
UIActivityViewController* shareVC = [[UIActivityViewController alloc] initWithActivityItems:shareStuff applicationActivities:Nil];
[self presentViewController:shareVC animated:YES completion:Nil];

You always have to pass an NSArray containing your shared content towards the Activity Controller.
Please note that, if you want to share an Image you have to pass in an UIImage and not UIImageView.

Easy solution, nice effect.

No comments:

Post a Comment