<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhone Blog by Aman &#187; Example Project</title>
	<atom:link href="http://amanpages.com/category/sample-iphone-example-project/feed/" rel="self" type="application/rss+xml" />
	<link>http://amanpages.com</link>
	<description>Pages on iPhone application development and opportunities from a developer&#039;s perspective</description>
	<lastBuildDate>Wed, 28 Apr 2010 10:44:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iPhone Facebook Connect: How Do I publish feed with FacebookAgent</title>
		<link>http://amanpages.com/sample-iphone-example-project/iphone-facebook-connect-how-do-i-publish-feed-with-facebookagent/</link>
		<comments>http://amanpages.com/sample-iphone-example-project/iphone-facebook-connect-how-do-i-publish-feed-with-facebookagent/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 21:45:44 +0000</pubDate>
		<dc:creator>Aman</dc:creator>
				<category><![CDATA[Example Project]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebookagent]]></category>

		<guid isPermaLink="false">http://amanpages.com/?p=201</guid>
		<description><![CDATA[<img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><br/>I planned to write a series of &#8220;How Do I&#8230;&#8221;s with Facebook Connect. Certainly the primary target is YOU but it will also work as a reference to me as well  
The first article will be on publishing a feed. 
So lets start&#8230;!
App Requirement Spec

 Option to login/logout to Facebook
Option to publish a feed [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fiphone-facebook-connect-how-do-i-publish-feed-with-facebookagent%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fiphone-facebook-connect-how-do-i-publish-feed-with-facebookagent%2F" height="61" width="51" /></a></div><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><br/><p>I planned to write a series of &#8220;How Do I&#8230;&#8221;s with Facebook Connect. Certainly the primary target is YOU but it will also work as a reference to me as well <img src='http://amanpages.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The first article will be on publishing a feed. </p>
<p>So lets start&#8230;!</p>
<h2>App Requirement Spec</h2>
<ol>
<li> Option to login/logout to Facebook</li>
<li>Option to publish a feed with:</li>
<ul>
<li>With an image with link</li>
<li>Action link</li>
</ul>
</ol>
<h2>Get FacebookAgent code</h2>
<p>Checkout the latest code from <a href="http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/">Google Code project</a>. The checkout url is:</p>
<p><span style="font-family:courier new;font-weight:bold;text-style:italic"><i>svn checkout http://iphone-facebook-twitter-connect-easy-integration-tool.googlecode.com/svn/trunk/ iphone-facebook-twitter-connect-easy-integration-tool-read-only</i></span></p>
<h2>Create a project</h2>
<p>Open up the xcode project and create a view based application; name it &#8220;FacebookFeedPublish&#8221;</p>
<h2>Add FacebookAgent code to project</h2>
<p>Right click on the project. <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>Select Add->Existing File</i></span>. Select the <strong>&#8220;xutils&#8221;</strong> folder from the checked out code. </p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-17.png" alt="Picture 17.png" border="0" width="333" height="238" /></p>
<p>Do not copy. </p>
<h2> Add JSON libraries</h2>
<p>Right click on the project. <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>Select Add->Existing File</i></span>. Select the <strong>&#8220;JSON&#8221;</strong> folder from the checked out <strong>xutils-example</strong> project. </p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-19.png" alt="Picture 19.png" border="0" width="294" height="174" /></p>
<p>Do not copy this either.</p>
<p>Build the project. It should build with no error.</p>
<h2>Initialize FacebookAgent</h2>
<p>Edit <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>FacebookPublishFeedAppDelegate.m</i></span>.</p>
<p>import FacebookAgent.h at the top.</p>
<pre name = "code"  class="c++">#import FacebookAgent.h</pre>
<p>Add the following line in <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>applicationDidFinishLaunching</i></span> method:</p>
<pre name = "code"  class="c++">
// initiazlie FacebookAgent
[[FacebookAgent sharedAgent]  initializeWithApiKey:@"YOUR_API_KEY"
							ApiSecret:@"YOUR_API_SECRET"
							ApiProxy:nil];
</pre>
<p>You have to put your Facebook Application api key and secret.  Just incase you are not sure about this, create a Facebook application from <a href="http://www.facebook.com/developers/createapp.php">http://www.facebook.com/developers/createapp.php</a>. After creating one, you will get api key and secret. Copy and paste those value in the above code.</p>
<h2>Prepare FacebookConnectDelegate handler</h2>
<p>We can use <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>FacebookAgent</i></span> in multiple view controllers. Very likely we will use it in many places. We have to override and define many delegate methods in each view controllers where we like to use FacebookAgent.</p>
<p>To simplify the process, we well create a <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>UIViewController</i></span> subclass which will define all the FacebookAgentDelegate methods. Our view controller class will extend this class and override only the required ones.</p>
<p>Add a new file of<span style="font-family:courier new;font-weight:bold;text-style:italic"><i> UIViewController</i></span> subclass. Name it <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>MyCustomController</i></span>.</p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-23.png" alt="Picture 23.png" border="0" width="434" height="318" /> </p>
<p> Uncheck  &#8220;With xib for user interface&#8221;.</p>
<p>Implement FacebookAgentDelegate protocol:</p>
<pre name = "code"  class="c++">
#import "FacebookAgent.h"

@interface MyCustomController : UIViewController<FacebookAgentDelegate> {

}
</pre>
<p>Now define the protocol methods:</p>
<pre name = "code"  class="c++">
#pragma mark FacebookAgentDelegate
- (void) facebookAgent:(FacebookAgent*)agent statusChanged:(BOOL) success{}
- (void) facebookAgent:(FacebookAgent*)agent didLoadInfo:(NSDictionary*) info{}
- (void) facebookAgent:(FacebookAgent*)agent didLoadFriendList:(NSArray*) data onlyAppUsers:(BOOL)yesOrNo{}
- (void) facebookAgent:(FacebookAgent*)agent didLoadPermissions:(NSArray*) data{}
- (void) facebookAgent:(FacebookAgent*)agent didLoadFQL:(NSArray*) data{}
- (void) facebookAgent:(FacebookAgent*)agent permissionGranted:(FacebookAgentPermission)permission{}
- (void) facebookAgent:(FacebookAgent*)agent photoUploaded:(NSString*) pid{}
- (void) facebookAgent:(FacebookAgent*)agent requestFaild:(NSString*) message{}
- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn{}
- (void) facebookAgent:(FacebookAgent*)agent dialog:(FBDialog*)dialog didFailWithError:(NSError*)error{}
</pre>
<p>Then edit <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>FacebookPublishFeedViewController.h</i></span> file and make it extend to the newly created class:</p>
<p>Build the project, it should build without any error.</p>
<h2>Enable login/logout option</h2>
<p>Add a button to the view.  Set its image for default state &#8220;Connect_iphone.png&#8221;. </p>
<p>Press &#8216;cmd + =&#8217; to adjust the size.</p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-21.png" alt="Picture 21.png" border="0" width="396" height="164" /></p>
<p>Set selected state button  &#8220;Logout_iphone.png&#8221;.</p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-22.png" alt="Picture 22.png" border="0" width="397" height="141" /></p>
<p>These images are downloaded from Facebook site and available in FacebookAgent code base.</p>
<h2>Connecting the button</h2>
<p>Edit <span style="font-family:courier new;font-weight:bold;text-style:italic"><i>FacebookPublishFeedViewController</i></span> class.</p>
<p>Create an IBOutlet connect it with the button.<br />
Then create an IBAction method and set it as button onTouchUpInside handler.</p>
<pre name = "code"  class="c++">
#import <UIKit/UIKit.h>
#import "MyCustomController.h"

@interface FacebookPublishFeedViewController : MyCustomController {
	UIButton* btnFbConnect;
}
- (IBAction)OnFBConnect:(id)sender;
@property(nonatomic, retain) IBOutlet UIButton* btnFbConnect;
@end
</pre>
<p>In OnFBConnect method we will login to facebook. If already connected we will sign out. So, method definition will be like this:</p>
<pre name = "code"  class="c++">
#pragma mark actions
- (IBAction)OnFBConnect:(id)sender{
	if([[FacebookAgent sharedAgent] isLoggedIn]){
		[[FacebookAgent sharedAgent] logout];
	}else {
		[[FacebookAgent sharedAgent] login];
	}
}
</pre>
<h2>Update connect button state</h2>
<p>Override the following method like below in FacebookPublishFeedViewController class:</p>
<pre name = "code"  class="c++">
#pragma mark FacebookAgentDelegate method
- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn{
	if(loggedIn){
		btnFbConnect.selected = YES;
	}else {
		btnFbConnect.selected = NO;
	}
}
</pre>
<p>This code will update the button image according to login status.</p>
<p>Run the app and connect to Facebook by clicking the button&#8230;. Oops button state is not changed! Add the following line in MyCustomController class viewLoaded method:</p>
<pre name = "code"  class="c++">
- (void)viewDidLoad {
    [super viewDidLoad];
	[FacebookAgent sharedAgent].delegate = self;
}
</pre>
<p>Now build and run&#8230; after login or logout now button image is updated accordingly.</p>
<h2>Publish Feed</h2>
<p>Add another Round button and add touch up inside handler in FacebookPublishFeedViewController class in this way:</p>
<pre name = "code"  class="c++">
- (IBAction)OnFBPublishFeed:(id)sender{
	[[FacebookAgent sharedAgent] publishFeedWithName:@"Hello Facebook!"
			captionText:@"This is a test publish"
			imageurl:@"http://xapplab.com/images/appss/puzzleshot/puzzleshot-icon.png"
			 linkurl:@"http://itunes.apple.com/app/puzzleshot/id343659310?mt=8"
			userMessagePrompt:@"Whats on your mind?"
			actionLabel:@"Play PuzzleShot"
			actionText:@"PuzzleShot!"
			actionLink:@"http://itunes.apple.com/app/puzzleshot/id343659310?mt=8"];
}
</pre>
<p>The feed will look this:</p>
<p><img src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/wordpress-blog-uploadPicture-26.png" alt="Picture 26.png" border="0" width="321" height="480" /></p>
<p>Thats it! </p>
<p>Next article will be on showing logged in user information and image. But let me manage some time first <img src='http://amanpages.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Download the project source :<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/04/FacebookPublishFeed.zip" title="FacebookPublishFeed.zip">FacebookPublishFeed.zip</a></p>
<p>Don&#8217;t forget to change api key and secret to run the project correctly!</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fiphone-facebook-connect-how-do-i-publish-feed-with-facebookagent%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fiphone-facebook-connect-how-do-i-publish-feed-with-facebookagent%2F" height="61" width="51" /></a></div><div align="left" style="float:left;padding:5px 5px 0px 0px;"><a name="fb_share" type="button_count" share_url="http://amanpages.com/sample-iphone-example-project/iphone-facebook-connect-how-do-i-publish-feed-with-facebookagent/"></a></div><fb:share-button href="http://amanpages.com/sample-iphone-example-project/iphone-facebook-connect-how-do-i-publish-feed-with-facebookagent/" type="button_count"></fb:share-button>]]></content:encoded>
			<wfw:commentRss>http://amanpages.com/sample-iphone-example-project/iphone-facebook-connect-how-do-i-publish-feed-with-facebookagent/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Multiple login for TwitterAgent</title>
		<link>http://amanpages.com/sample-iphone-example-project/multiple-login-for-twitteragent/</link>
		<comments>http://amanpages.com/sample-iphone-example-project/multiple-login-for-twitteragent/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 11:33:12 +0000</pubDate>
		<dc:creator>Aman</dc:creator>
				<category><![CDATA[Example Project]]></category>
		<category><![CDATA[iPhone App Development]]></category>
		<category><![CDATA[twitteragent]]></category>

		<guid isPermaLink="false">http://amanpages.com/?p=187</guid>
		<description><![CDATA[<img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/>I received some requests on multiple login option for TwitterAgent and updated the agent there by. Now a logout option is added to login again with a different userid.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fmultiple-login-for-twitteragent%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fmultiple-login-for-twitteragent%2F" height="61" width="51" /></a></div><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/><p>TwitterAgent is updated and a new feature is added by your request. I received some requests on multiple login option for TwitterAgent and updated the agent there by. Now a logout option is added to login again with a different userid.</p>
<h2>Add twitter agent code to your project</h2>
<p>You can checkout the latest code from the google project or can use the folder available in attached demo project below.<br />
Paste the xutils folder into your project directory.</p>
<p>Now, right click on the project in xcode and add the xutils folder.</p>
<h2>Add SBJSON</h2>
<p>SBJSON is also required for the project. You can have one copy of sbjson source in the attached project.</p>
<h2>Add twit code</h2>
<p>Add a button and in its event handler method add the following lines:</p>
<pre name = "code"  class="c++">[[TwitterAgent defaultAgent] twit];</pre>
<p>After logging in, you will find a new button available on top right corner, that is the logout button!</p>
<div id="attachment_188" class="wp-caption alignnone" style="width: 290px"><a href="http://amanpages.com/wordpress/wp-content/uploads/2010/04/twitter-agent-logout-option.png"><img class="size-full wp-image-188" title="twitter-agent-logout-option" src="http://amanpages.com/wordpress/wp-content/uploads/2010/04/twitter-agent-logout-option.png" alt="" width="280" height="213" /></a><p class="wp-caption-text">TwitterAgent Logout option</p></div>
<p>On the next version, there will be option to manage batch twit account! Don&#8217;t forget to check back soon!</p>
<blockquote><p><a title="Twitter-Agent-Logout-Example" href="http://amanpages.com/wordpress/wp-content/uploads/2010/04/TwitterAgentLogoutExample.zip">Download Demo project</a></p></blockquote>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fmultiple-login-for-twitteragent%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fmultiple-login-for-twitteragent%2F" height="61" width="51" /></a></div><div align="left" style="float:left;padding:5px 5px 0px 0px;"><a name="fb_share" type="button_count" share_url="http://amanpages.com/sample-iphone-example-project/multiple-login-for-twitteragent/"></a></div><fb:share-button href="http://amanpages.com/sample-iphone-example-project/multiple-login-for-twitteragent/" type="button_count"></fb:share-button>]]></content:encoded>
			<wfw:commentRss>http://amanpages.com/sample-iphone-example-project/multiple-login-for-twitteragent/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TwitterAgent Tutorial : Tweet from iPhone app in one line code with auto tinyURL</title>
		<link>http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/</link>
		<comments>http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 10:32:02 +0000</pubDate>
		<dc:creator>Aman</dc:creator>
				<category><![CDATA[Example Project]]></category>
		<category><![CDATA[iPhone App Development]]></category>
		<category><![CDATA[twitteragent]]></category>

		<guid isPermaLink="false">http://amanpages.com/?p=111</guid>
		<description><![CDATA[<img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/>Integrate Twitter from you iPhone application using TwitterAgent. With TwitterAgent, you can do it by single line of code! Also you can auto shorten any url using tinyURL and attach with past just passing one extra parameter!]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ftwitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ftwitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl%2F" height="61" width="51" /></a></div><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/><blockquote><p><strong>GET THE LATEST CODE FROM HERE:<a href=" http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/"> http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/</a><br />
PLEASE JOIN THE PROJECT<br />
</strong></p></blockquote>
<blockquote><p><strong>** For sample project, see the comments at the end of this post **</strong></p></blockquote>
<p>Perhaps, you have used the <a href="http://amanpages.com/iphone-app-development-core-sdk-cocoa/facebookagent-update-now-upload-a-photo-and-then-change-status-in-a-single-call-using-facebook-connect-for-iphone/">FacebookAgent</a> in your apps. I gratefully thank the fellows from  <a href="http://iphonedevsdk.com/" target="_blank">iphonedevsdk.com</a> and other iPhone developers who mailed me saying the class helped them. These are actual inspiration of sharing code with all.</p>
<p>Now, I would like to share my TwitterAgent class with you. Using TwitterAgent you can now integrate twitter in your iPhone app seamlessly. Additionally, you can also specify a URL and can make it tinyURL on the fly just passing an extra parameter!</p>
<p>Here are the steps:</p>
<p>1. Download <a href='http://amanpages.com/wordpress/wp-content/uploads/2010/01/TwitterAgent.zip'>TwitterAgent</a> and <a href='http://amanpages.com/wordpress/wp-content/uploads/2010/01/BusyAgent.zip'>BusyAgent</a> and add them into your project.</p>
<p>2. Import TwitterAgent.h in the file where we want to use</p>
<p>3. Now call any of these function, they are self explanatory!</p>
<pre class="c++" name="code">
[[TwitterAgent defaultAgent] twit ];

[[TwitterAgent defaultAgent] twit:@"Search with google!" ];

[[TwitterAgent defaultAgent] twit:@"Search with google!" withLink:@"http://www.google.com" makeTiny:NO];

[[TwitterAgent defaultAgent] twit:@"Search with google!" withLink:@"http://www.google.com" makeTiny:YES];
</pre>
<p>Screenshots:</p>
<div id="attachment_112" class="wp-caption alignnone" style="width: 294px"><a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-1.png"><img class="size-full wp-image-112" title="Login To Twitter" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-1.png" alt="" width="284" height="198" /></a><p class="wp-caption-text">Login To Twitter</p></div>
<p>You only need to login once in one session. Login information will be saved to the device and will be used next time the application starts.</p>
<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-7.png"><img class="size-full wp-image-113 " title="[[TwitterAgent defaultAgent] twit];" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-7.png" alt="" width="292" height="233" /></a>
<pre class="c++" name="code">
[[TwitterAgent defaultAgent] twit];
</pre>
<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-6.png"><img class="size-full wp-image-114 " title="twit with message" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-6.png" alt="" width="289" height="227" /></a>
<pre class="c++" name="code">
[[TwitterAgent defaultAgent] twit:@"Search with google!"];
</pre>
<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-8.png"><img class="size-full wp-image-115" title="Twit with message and URL" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-8.png" alt="" width="286" height="223" /></a>
<pre class="c++" name="code">
[[TwitterAgent defaultAgent] twit:@"Search with google!" withLink:@"http://www.google.com" makeTiny:NO];
</pre>
<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-5.png"><img class="size-full wp-image-117" title="Twit with message and tiny url" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-5.png" alt="" width="287" height="225" /></a>
<pre class="c++" name="code">
[[TwitterAgent defaultAgent] twit:@"Search with google!" withLink:@"http://www.google.com" makeTiny:YES];
</pre>
<p>Hope it will come into your help. Cheers!</p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ftwitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ftwitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl%2F" height="61" width="51" /></a></div><div align="left" style="float:left;padding:5px 5px 0px 0px;"><a name="fb_share" type="button_count" share_url="http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/"></a></div><fb:share-button href="http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/" type="button_count"></fb:share-button>]]></content:encoded>
			<wfw:commentRss>http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>FacebookAgent: Easy way to integrate facebook connect in iPhone Apps and write minimum code to publish feed, change status etc!</title>
		<link>http://amanpages.com/sample-iphone-example-project/facebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status/</link>
		<comments>http://amanpages.com/sample-iphone-example-project/facebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 18:38:05 +0000</pubDate>
		<dc:creator>Aman</dc:creator>
				<category><![CDATA[Example Project]]></category>
		<category><![CDATA[iPhone App Development]]></category>
		<category><![CDATA[facebookagent]]></category>

		<guid isPermaLink="false">http://amanpages.com/?p=59</guid>
		<description><![CDATA[<img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/>FacebookAgent: Use it to skip code rewrite, write less code, easy integration of facebook connect without any project settings change. Publish feed, change status, upload photo without writing code for login, extended permission etc!! Above all, use the source code freely without any restriction even for commercial purpose! Free and Open!]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ffacebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ffacebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status%2F" height="61" width="51" /></a></div><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/><blockquote><p><strong>GET THE LATEST CODE FROM HERE:<a href=" http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/"> http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/</a><br />
PLEASE JOIN THE PROJECT<br />
</strong></p></blockquote>
<p>Today most of the applications we build have a common feature: Socialize! One common way to achieve this my integrating Facebook within the app.</p>
<p>In my earlier <a href="http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/">post</a> I have shared a helper class for paginating data. Today I will share how I integrate facebook connect in iPhone apps. I humble admit I am a lazy, if not busy, developer who doesn&#8217;t like to write same code again again.</p>
<p>For iPhone applications <a href="http://developers.facebook.com/connect.php">FacebookConnect</a> is the only way to integrate facebook social features. Facebook team has developed a sdk for iPhone. A sample code showing the use and integration of Facebook Connect in your application. This is quite simple and also tons of tutorials, forums, e-books and videos are out here on the web.</p>
<p>Well, I&#8217;m not gonna add few more grams on that! Rather I am going to share how I integrates facebook connects into my apps.</p>
<p>Firstly, let us see what are the steps to add facebook connect. You can also check out this tutorial on <a href="http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone">facebook wiki</a> or watch the video <a href="http://vimeo.com/3616452">Implement Facebook Connect on the iPhone in 5 minutes</a>.</p>
<p>Basically the steps for publishing a feed are:</p>
<p>1. Download the <a href="http://github.com/facebook/facebook-iphone-sdk/">sdk</a>.</p>
<p>2. Add the connect source file in your project.<br />
project<br />
3. Update the  settings to make FBConnect.h in you header path.</p>
<p>4. In the controller class, have session member variable, many delegate methods.</p>
<p>5. Have a login button to show the login prompt.</p>
<p>6. Once logged in, prepare an attachment json string and show the feed dialog.</p>
<p>These steps are quite simple but if you are a busy programmer and need to work on many projects these steps may be little bothering since you have to rewrite all the codes for loggin in, showing dialogs, handle login events etc.</p>
<p>So, I just encapsulated these repetitive work into a class named FacebookAgent and defined a simple protocol to work on.</p>
<p>Lets see how we can use it.</p>
<p><strong>Objective</strong>: Create a simple view based application and publish a feed using FacebookAgent.</p>
<p>1. Download this folder     <a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/FacebookAgent.zip">FacebookAgent.zip</a>.</p>
<p>It also includes facebook connect sdk. So you don&#8217;t need to add this sdk elsewhere or even update any project settings for this purpose.</p>
<p>2. Create a new project, name it FacebookAgentTest. Righ click on the project in the XCode and select Add existing files. Add the FacebookAgent Folder to your classes. Check copy the source files.</p>
<div id="attachment_66" class="wp-caption alignnone" style="width: 310px"><a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-22.png"><img class="size-medium wp-image-66" title="Add FacebookAgent folder to your project" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-22-300x283.png" alt="" width="300" height="283" /></a><p class="wp-caption-text">Add FacebookAgent folder to your project</p></div>
<p>3.  In the FacebookAgentTestViewController.h, import FacebookAgent.h and implement protocol FacebookAgentDelegate.</p>
<pre  name = "code" class="c++">@interface FacebookAgentTestViewController : UIViewController {
...</pre>
<p>4. Declare a member variable of type FacebookAgent.</p>
<pre name = "code"  class="c++">FacebookAgent* fbAgent;</pre>
<p>5. Open FacebookAgentTest.m and initialize fbAgent in viewDidLoad method.</p>
<pre  name = "code"  class="c++">fbAgent = [[FacebookAgent alloc] initWithApiKey:@"PLACE YOUR FACEBOOK APPLICATION API KEY"
										  ApiSecret:@"PLACE YOUR FACEBOOK APPLICATION API SECRET"
										   ApiProxy:nil];
	fbAgent.delegate = self;</pre>
<p>6. Declare an IBAction method in the FacebookAgentTest.h file.</p>
<pre  name = "code" class="c++">-(IBAction)updateStatus:(id)sender;</pre>
<p>7. Define the above method in FacebookAgentTest.m file.</p>
<pre  name = "code" class="c++">-(IBAction)updateStatus:(id)sender{
}</pre>
<p>8. Open FacebookAgentTestViewController.xib and add a button in the view and connect the above method on its touchesUpInside signal.</p>
<p><a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-23.png"><img class="alignnone size-medium wp-image-67" title="Picture 23" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-23-300x219.png" alt="" width="300" height="219" /></a></p>
<p>9. Now just add the following lines in the updateStatus method to publish a feed!</p>
<pre  name = "code" class="c++">-(IBAction)updateStatus:(id)sender{
[fbAgent publishFeedWithName:@"Hellow world"
					 captionText:@"how are you?"
						imageurl:@"http://amanpages.com/wordpress/wp-content/uploads/2009/12/logo2.png"
						 linkurl:@"http://amanpages.com/"
			   userMessagePrompt:@"What do you think:"];
}</pre>
<p>This code will first check if the user is logged in. If logged in it will show the feed dialog.<br />
If the user is not logged in already, first the login dialog will be shown, after logging in, the feed dialog will be shown automatically!</p>
<p>But one minute, there is one require method in the FacebookAgentDelegate protocol. So, you need to define this:</p>
<pre  name = "code" class="c++">- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn{
}</pre>
<p>Above method is called when the user logs in or logs out of the facebook. If you use any login button which is very likely, you may change the button title here.</p>
<p>10. Try updating your status. For this use this line:</p>
<pre  name = "code" class="c++">[fbAgent setStatus:@"status from iPhone 1"];</pre>
<p>This will first check if the user is logged in. if not logged in, then it will show the login prompt first.<br />
After log in it will check if extended permission is enabled for this app. if not it will show the permission dialog.<br />
Having given the permission, it will change the user status.</p>
<p>BUT.</p>
<p>11. You need to two more FacebookAgentDelegate method if you want to change status:</p>
<pre  name = "code" class="c++">- (void) facebookAgent:(FacebookAgent*)agent requestFaild:(NSString*) message{
}
- (void) facebookAgent:(FacebookAgent*)agent statusChanged:(BOOL) success{
}</pre>
<p>12. Thats all <img src='http://amanpages.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Run the app!</p>
<p>You can look into the FacebookAgent.h for more detail. It is well documented. If you still have some question shoot here or drop me mail.<br />
Feel free to use this classes without any restriction but I will appreciate if you let me know in which app you are using it <img src='http://amanpages.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What can be done now using FacebookAgent:<br />
1. Fetch user name:<br />
For this after initialization, set shouldFetchUsernameAfterLogin = YES.</p>
<pre  name = "code" class="c++">fbAgent.shouldFetchUsernameAfterLogin = YES</pre>
<p>and also define the corresponding delegate method:</p>
<pre  name = "code"  class="c++">- (void) facebookAgent:(FacebookAgent*)agent didLoadName:(NSString*) name{
    //use the name
}</pre>
<p>2. Make your own attachment and publish a feed.</p>
<pre  name = "code" class="c++">// this method has some over loaded versions too
- (void) publishFeed:(NSString*)attachement;</pre>
<p>3. Publish feed by passing, name, caption, image and link url.</p>
<pre  name = "code" class="c++">// this method has some over loaded versions too
/**
 * Let the agent make attachement for you. You just pass the information
 *
 */
- (void) publishFeedWithName:(NSString*)name
			 captionText:(NSString*)caption
					   imageurl:(NSString*)url
						linkurl:(NSString*)href
			  userMessagePrompt:(NSString*)prompt;</pre>
<p>4.  upload a photo</p>
<pre  name = "code" class="c++">- (void) uploadPhoto:(NSString*)imageurl;</pre>
<p>6. ask for extended permission</p>
<pre  name = "code" class="c++">- (void) askPermission;</pre>
<p>7. login and logout</p>
<pre  name = "code" class="c++">- (void) login;
- (void) logout;</pre>
<p>The delegates also offers some handy callback options like:</p>
<pre name = "code"  class="c++">/**
 * Must define this method if setStatus is called
 *
 * This method is called when user status is changed either successfully or not
 */
- (void) facebookAgent:(FacebookAgent*)agent statusChanged:(BOOL) success;

/**
 * Must define this method if shouldFetchUsernameAfterLogin is set YES
 *
 * This method is called after the agent fetched facebook profile name
 */
- (void) facebookAgent:(FacebookAgent*)agent didLoadName:(NSString*) name;

/**
 * Must define this method if uploadPhoto is called
 *
 * This method is called after photo is uploaded
 */
- (void) facebookAgent:(FacebookAgent*)agent photoUploaded:(NSString*) pid;

/**
 * Must impement this method if any of the above method is defined
 *
 * This method is called if the agent fails to perform any of the above three actions
 */
- (void) facebookAgent:(FacebookAgent*)agent requestFaild:(NSString*) message;

@required

/**
 * This method is called if after login or logout
 */
- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn;</pre>
<p>Here is the demo project. DONT FORGET TO ADD YOUR key and secret!!<br />
<a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/FacebookAgentTest.zip">FacebookAgentTest</a></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ffacebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Ffacebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status%2F" height="61" width="51" /></a></div><div align="left" style="float:left;padding:5px 5px 0px 0px;"><a name="fb_share" type="button_count" share_url="http://amanpages.com/sample-iphone-example-project/facebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status/"></a></div><fb:share-button href="http://amanpages.com/sample-iphone-example-project/facebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status/" type="button_count"></fb:share-button>]]></content:encoded>
			<wfw:commentRss>http://amanpages.com/sample-iphone-example-project/facebookagent-easy-way-to-integrate-facebook-connect-in-iphone-apps-and-write-minimum-code-to-publish-feed-change-status/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Helper class for showing records with pagination for iPhone sdk app</title>
		<link>http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/</link>
		<comments>http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 14:02:01 +0000</pubDate>
		<dc:creator>Aman</dc:creator>
				<category><![CDATA[Example Project]]></category>
		<category><![CDATA[iPhone App Development]]></category>
		<category><![CDATA[helper]]></category>

		<guid isPermaLink="false">http://amanpages.com/?p=20</guid>
		<description><![CDATA[<img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/>A helper class for showing records in pages. This can be used for showing comments, shouts, recent news etc with some buttons like next, previous.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fhelper-class-for-showing-records-with-pagination-for-iphone-sdk-app%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fhelper-class-for-showing-records-with-pagination-for-iphone-sdk-app%2F" height="61" width="51" /></a></div><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/samplecode.png" width="36" height="36" alt="" title="Example Project" /><img src="http://amanpages.com/wordpress//wp-content/uploads/icons/32_iphone.png" width="40" height="40" alt="" title="iPhone App Development" /><br/><p>We often need to add social features in our iPhone apps. Adding features like commenting, shouts etc are very common. These type of data are usually shown<br />
with pagination with buttons like next, previous etc.</p>
<p>To reduce the overhead of creating this functionality again and again we may encapsulate the common functions in a class. So did I for my applications.</p>
<p>I have created a class named PaginationAgent. After loading records it calls related methods of its delegate which should implement protocol PaginationAgentDeleagte.</p>
<p>Additionally two php files are needed. One to return the total number of records and another one is to fetch the page data. They must be named respectively as</p>
<ul>
<li> get_total_number_of_records.php</li>
<li>get_records.php</li>
</ul>
<p>Lets see an example.</p>
<p>First, I have created a simple view based project &#8220;Pagination&#8221; and designed the view as u see:</p>
<div id="attachment_21" class="wp-caption aligncenter" style="width: 265px"><a href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-21.png"><img class="size-medium wp-image-21 " title="Interface" src="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Picture-21-255x300.png" alt="" width="255" height="300" /></a><p class="wp-caption-text">Create a similar view using Interface Builder</p></div>
<p>1. Added a button to show previous page data</p>
<p>2. One button to reload the data.</p>
<p>3. Another to show data on next page.</p>
<p>4. Added a UITable which will show the result.</p>
<p>In PaginationViewController.h, imported PaginationAgent.h file and declared:</p>
<pre name="code" class="c++">
PaginationAgent* objPagination;
</pre>
<p>Now lets see how to initialize it. In the viewDidLoad method I initialized this like this:</p>
<pre  name="code" class="c++">objPagination = [[PaginationAgent alloc] init];
objPagination.delegate = self;
objPagination.remoteApiBasePath = @"http://your.server/path/to/folder";</pre>
<p>remoteApiBasePath must be set to the location where the server side php files are placed.<br />
No trailing slash.</p>
<p>PaginationAgentDelegate protocol declares the following functions to be overridden by the Delegate:</p>
<pre  name="code" class="c++">/**
* This method is called when the busystate is changed.
* You can do something like disable/enable the buttons, grayout etc
* based on the isBusy value.
*/
-(void)paginationAgent:(PaginationAgent*)agent updateBusyMode:(BOOL)isBusy;

/**
* Called when total data count is received if shouldReloadAtFirstPage is set NO.
*/
-(void)paginationAgent:(PaginationAgent*)agent totalDataCountReceived:(int)dataCount;

/**
* Called when page data is loaded. You may set your table dataSource here and realod
* reload the table.
*/
-(void)paginationAgent:(PaginationAgent*)agent pageDataReceived:(NSArray*)data;

/**
* Called if server sends malformed data
*/
-(void)paginationAgent:(PaginationAgent*)agent onPaginationServerError:(NSString*)message;

/**
* Called if connection failed. It may occur due to poor or no internet connectivity
*/
-(void)paginationAgent:(PaginationAgent*)agent onPaginationConnectionError:(NSString*)message;</pre>
<p>The php files must return data in json format and must use the format as used:</p>
<pre  name="code" class="php">
<?

// get data from database

	$data = array('success'=>1,'message'=>'Success','data'=>33);
	echo json_encode($data);

?>
</pre>
<pre  name="code" class="php">
...
...
$data = array('success'=>1,'message'=>'Got data','data'=>$rows);

echo json_encode($data);
</pre>
<p>See the attached project for details. The php files are inside the folder &#8220;PHPFILES&#8221;.</p>
<p><a title="Pagination xCode project with PHP files" href="http://amanpages.com/wordpress/wp-content/uploads/2010/01/Pagination.zip">Pagination.zip</a></p>
<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fhelper-class-for-showing-records-with-pagination-for-iphone-sdk-app%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Famanpages.com%2Fsample-iphone-example-project%2Fhelper-class-for-showing-records-with-pagination-for-iphone-sdk-app%2F" height="61" width="51" /></a></div><div align="left" style="float:left;padding:5px 5px 0px 0px;"><a name="fb_share" type="button_count" share_url="http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/"></a></div><fb:share-button href="http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/" type="button_count"></fb:share-button>]]></content:encoded>
			<wfw:commentRss>http://amanpages.com/sample-iphone-example-project/helper-class-for-showing-records-with-pagination-for-iphone-sdk-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
