Social Network In iPhone


In this article I will create a Single View application. Here I use buttons from outlet. When we click on a button the Activity View Controller is called that is defined in a social framework. Using this we post an image or text in a single time multiple social site that is added in social framework.

To understand it we use the following.

Step 1

Here first we add the framework Social that is required to implement Facebook.

To import this framework we use the following.

Step 2

Click on the project and select Build Phase.


Step 3

Click on the "+" icon to add the framework.


Step 4

Now select the Social framework and click on the add button.


Step 5

Here we import an image in a bundle that was posted in multiple platforms.

Step 6

Now we write the code for each class.


#import <UIKit/UIKit.h>
@class SocialViewController;
@interface SocialAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SocialViewController *viewController;


#import "SocialAppDelegate.h"
#import "SocialViewController.h"
@implementation SocialAppDelegate
- (void)dealloc
[_window release];
[_viewController release];
[super dealloc];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[SocialViewController alloc] initWithNibName:@"SocialViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;


#import <UIKit/UIKit.h>
@interface SocialViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIButton *advancedButton;
- (IBAction)activityButtonPressed:(id)sender;


#import "SocialViewController.h"
#import <Social/Social.h>
@interface SocialViewController ()
@implementation SocialViewController
@synthesize advancedButton;
- (IBAction)activityButtonPressed:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
NSString *text = @"Lime Cat";
UIImage *image = [UIImage imageNamed:@"lime-cat"];
NSArray *activityItems = [NSArray arrayWithObjects:text,image , nil];
UIActivityViewController *avc = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.

Step 7

Finally we click on the run button to show the output.

Step 8

Output 1 in iPhone:


Here we click on the "Social Media" Button.

Output 2 in iPhone:


Now we click on the mail icon.

Output 3 in iPhone:


Here we add a contact.

Output 4 in iPhone:


Here we write a mail subject.

Output 5 in iPhone:


After clicking on the send button.

Output 6 in iPhone:

Output6-in-iPhone .png

Now we again run the app and post it on Twitter. To do that we click on the Twitter icon.

Output 7 in iPhone.


Output 8 in iPhone.


Now we again run the app and post it on Facebook. To do that we click on the Facebook icon.

Output 9 in iPhone


In the same way we can post it, print it, assign it and more.

Up Next
    Ebook Download
    View all
    View all