Social Network In iPhone

Introduction

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.

Build-phase-in-iphone.jpg

Step 3

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

frameworrk-in-iPhone.jpg

Step 4

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

Social-framework-in-iPhone.png

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.

SocialAppDelegate.h

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

SocialAppDelegate.m

#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;
}
@end

SocialViewController.h

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

SocialViewController.m

#import "SocialViewController.h"
#import <Social/Social.h>
@interface SocialViewController ()
@end
@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.
}
@end

Step 7

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

Step 8

Output 1 in iPhone:

Output1-in-iPhone.png

Here we click on the "Social Media" Button.

Output 2 in iPhone:

Output2-in-iPhone.png

Now we click on the mail icon.

Output 3 in iPhone:

Output3-in-iPhone.png

Here we add a contact.

Output 4 in iPhone:

Output4-in-iPhone.png

Here we write a mail subject.

Output 5 in iPhone:

Output5-in-iPhone.png

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.

Output7-in-iPhone.png

Output 8 in iPhone.

Output8-in-iPhone.png

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

Output 9 in iPhone

Output9-in-iPhone.png

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

Up Next
    Ebook Download
    View all
    Learn
    View all