<?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 Programming Tutorials &#187; ayanok</title>
	<atom:link href="/author/ayanok/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com</link>
	<description>iPhone Programming Tutorials</description>
	<lastBuildDate>Tue, 19 Nov 2013 19:34:46 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.2</generator>
	<item>
		<title>Adding block callbacks to the Facebook iOS SDK</title>
		<link>http://icodeblog.com/2011/07/19/adding-block-callbacks-to-the-facebook-ios-sdk/</link>
		<comments>http://icodeblog.com/2011/07/19/adding-block-callbacks-to-the-facebook-ios-sdk/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 16:28:31 +0000</pubDate>
		<dc:creator><![CDATA[ayanok]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Advanced]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=3139</guid>
		<description><![CDATA[If you are like me and love using blocks over delegates, then these code snippets will come in handy. After learning about blocks I have come to love to use them, especially using them for callbacks rather than using the old protocol/delegate methodology. These code snippets will allow you to use blocks as callbacks over delegates.
In a previous post <a href="/2011/03/28/facebook-sdk-posting-to-user-news-feed/"> Facebook SDK &#8211; Posting to User News Feed</a> I showed how to post various types of status&#8217;s to the  ...]]></description>
				<content:encoded><![CDATA[<p>If you are like me and love using blocks over delegates, then these code snippets will come in handy. After learning about blocks I have come to love to use them, especially using them for callbacks rather than using the old protocol/delegate methodology. These code snippets will allow you to use blocks as callbacks over delegates.</p>
<p>In a previous post <a href="/2011/03/28/facebook-sdk-posting-to-user-news-feed/"> Facebook SDK &#8211; Posting to User News Feed</a> I showed how to post various types of status&#8217;s to the logged in users news feed. These code snippets have been added to a <a href="https://github.com/ayanok/facebook-ios-sdk">forked version</a> of the official Facebook for iOS SDK. A sample of how to use the new block callbacks can be found within the <a href="https://github.com/ayanok/Andy-Yanok---Public-Sample-Code/tree/master/Facebook%20Demo">sample project</a> from the last post.</p>
<p>For more information on blocks, you can refer to the <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html">Apple document</a> discussing blocks in more detail.</p>
<p>Step 1: Modifying FBRequest Class for new callbacks<br />
First we will modify the FBRequest class. There are a few simple modifications that we need to create. Within the FBRequest.h file add the following:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>copy<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">void</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span>FBRequestCallback<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest<span style="color: #002200;">*</span>, <span style="color: #a61390;">id</span>, <span style="color: #400080;">NSError</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span>  <span style="color: #a61390;">BOOL</span> usesBlockCallback;
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>FBRequest<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> getRequestWithParams<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>params
                         httpMethod<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>httpMethod
                           callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block
                         requestURL<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>url;</pre></td></tr></table></div>

<p>In the FBRequest.m file add the following code:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@synthesize</span> FBRequestCallback <span style="color: #002200;">=</span> _FBRequestCallback;
<span style="color: #a61390;">@synthesize</span> usesBlockCallback;
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>FBRequest<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> getRequestWithParams<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>params
                         httpMethod<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>httpMethod
                           callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block
                         requestURL<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>url
<span style="color: #002200;">&#123;</span>
    FBRequest<span style="color: #002200;">*</span> request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequest alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    request.delegate <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    request.url <span style="color: #002200;">=</span> url;
    request.httpMethod <span style="color: #002200;">=</span> httpMethod;
    request.params <span style="color: #002200;">=</span> params;
    request.connection <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    request.responseText <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    request.FBRequestCallback <span style="color: #002200;">=</span> _block;
&nbsp;
    <span style="color: #a61390;">return</span> request;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>In the FBRequest class we are duplicating what they already have in the provided method but swapping out the delegate with a block. Out of personal preference I went with a single callback versus having an error and result callback. If there is no error we will be returning nil for the error parameter.</p>
<p>I also added a boolean property that will be used to determine which callback to use when processing the data when it has been returned from the Facebook servers.</p>
<p>Moving onto the &#8211; (void)handleResponseData:(NSData *)data; Method we need to add logic to pass the result request data onto the block callback.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>handleResponseData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>data <span style="color: #002200;">&#123;</span>
  <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>_delegate respondsToSelector<span style="color: #002200;">:</span>
      <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>request<span style="color: #002200;">:</span>didLoadRawResponse<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>_delegate request<span style="color: #002200;">:</span>self didLoadRawResponse<span style="color: #002200;">:</span>data<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>usesBlockCallback<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSError</span><span style="color: #002200;">*</span> error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
        <span style="color: #a61390;">id</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self parseJsonResponse<span style="color: #002200;">:</span>data error<span style="color: #002200;">:&amp;</span>amp;error<span style="color: #002200;">&#93;</span>;
        _FBRequestCallback<span style="color: #002200;">&#40;</span>self, result, error<span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>_delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>request<span style="color: #002200;">:</span>didLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span> ||
             <span style="color: #002200;">&#91;</span>_delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>request<span style="color: #002200;">:</span>didFailWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSError</span><span style="color: #002200;">*</span> error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
        <span style="color: #a61390;">id</span> result <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self parseJsonResponse<span style="color: #002200;">:</span>data error<span style="color: #002200;">:&amp;</span>amp;error<span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>self failWithError<span style="color: #002200;">:</span>error<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
        <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>_delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>request<span style="color: #002200;">:</span>didLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #002200;">&#91;</span>_delegate request<span style="color: #002200;">:</span>self didLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>result <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span> ? data <span style="color: #002200;">:</span> result<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>We are using the same logic as the standard delegate methodology, except we do not need to make a separate delegate call if there is an error. Within the block we have included result and an NSError parameter. That way you can handle the error logic within the same callback.</p>
<p>Finally within the dealloc method we need to release the block. Since we are using the block in objective-c we can simply use [_FBRequestCallback release]; You can also use Block_release(_FBRequestCallback); but since we are using it within Objective-C we can use the standard way of releasing an object.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>_FBRequestCallback release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_connection cancel<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_connection release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_responseText release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_url release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_httpMethod release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params release<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Step 2: Adding request methods with block callbacks</p>
<p>We want to include two new methods to the Facebook.h class. One method is for graph API requests, and one is for the the old REST API.</p>
<p>In the Facebook.h add the following two methods:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> requestWithGraphPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _graphPath
                       params<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params
                       method<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _method
                     callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> requestWithMethodName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _methodName
                     andParams<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params
                 andHttpMethod<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _method
                      callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block;</pre></td></tr></table></div>

<p>In the Facebook.m file add the following two method implementations:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> requestWithGraphPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _graphPath
                       params<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params
                       method<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _method
                     callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> fullURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>kGraphBaseURL stringByAppendingString<span style="color: #002200;">:</span>_graphPath<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;json&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;format&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>kSDK forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sdk&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>kSDKVersion forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sdk_version&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self isSessionValid<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>self.accessToken forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;access_token&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>_request release<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">//modify request to have block</span>
    _request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequest getRequestWithParams<span style="color: #002200;">:</span>_params
                                     httpMethod<span style="color: #002200;">:</span>_method
                                       callback<span style="color: #002200;">:</span>_block
                                     requestURL<span style="color: #002200;">:</span>fullURL<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_request connect<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> requestWithMethodName<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _methodName
                     andParams<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params
                 andHttpMethod<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _method
                      callback<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> _block
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> fullURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>kRestserverBaseURL stringByAppendingString<span style="color: #002200;">:</span>_methodName<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;json&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;format&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>kSDK forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sdk&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>kSDKVersion forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;sdk_version&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self isSessionValid<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>_params setValue<span style="color: #002200;">:</span>self.accessToken forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;access_token&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>_request release<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">//modify request to have block</span>
    _request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequest getRequestWithParams<span style="color: #002200;">:</span>_params
                                     httpMethod<span style="color: #002200;">:</span>_method
                                       callback<span style="color: #002200;">:</span>_block
                                     requestURL<span style="color: #002200;">:</span>fullURL<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>_request connect<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Once again we are duplicating the previously implemented methods by Facebook. The only difference is changing the request method. As you notice we are now using the methods we implemented in the FBRequest class.</p>
<p>Now that we have everything implemented that we need in the Facebook SDK we can use our awesome new block callbacks! The following snippet will return the logged in users friends!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">    <span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>params <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>facebook requestWithGraphPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;me/friends&quot;</span>
                                    params<span style="color: #002200;">:</span>params
                                    method<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;GET&quot;</span>
                                  callback<span style="color: #002200;">:^</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span>request, <span style="color: #a61390;">id</span> result, <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;friends %@&quot;</span>, result<span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>result isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            friendsList <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>result objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;data&quot;</span><span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span>;
            <span style="color: #002200;">&#91;</span>table reloadData<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#125;</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2011/07/19/adding-block-callbacks-to-the-facebook-ios-sdk/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Facebook SDK &#8211; Posting to User News Feed</title>
		<link>http://icodeblog.com/2011/03/28/facebook-sdk-posting-to-user-news-feed/</link>
		<comments>http://icodeblog.com/2011/03/28/facebook-sdk-posting-to-user-news-feed/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 21:16:32 +0000</pubDate>
		<dc:creator><![CDATA[ayanok]]></dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Intermediate]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=2952</guid>
		<description><![CDATA[
Hello, I&#8217;m <a href="http://www.andrewyanok.com/indexay.htm">Andy Yanok</a> (<a href="http://www.twitter.com/ayanok1">Twitter</a>) and I recently finished working on <a href="http://www.friendedapp.com/">Friended for Facebook</a>.  Many applications use Facebook for posting content from their respective applications, there could be infinite items that a developer would like to post to users feeds whilst using their applications but today we will be focusing on posting a link to a users feed.
In order to get started using the Facebook SDK &#38; API&#8217;s you will need to download the latest copy  ...]]></description>
				<content:encoded><![CDATA[<p><img src="/wp-content/uploads/2011/03/Facebook-Demo-Posts.png" alt="" /><br />
Hello, I&#8217;m <a href="http://www.andrewyanok.com/indexay.htm">Andy Yanok</a> (<a href="http://www.twitter.com/ayanok1">Twitter</a>) and I recently finished working on <a href="http://www.friendedapp.com/">Friended for Facebook</a>.  Many applications use Facebook for posting content from their respective applications, there could be infinite items that a developer would like to post to users feeds whilst using their applications but today we will be focusing on posting a link to a users feed.</p>
<p>In order to get started using the Facebook SDK &amp; API&#8217;s you will need to download the latest copy of the <a title="Facebook SDK" href="https://github.com/facebook/facebook-ios-sdk" target="_blank">Facebook SDK</a> for iOS.  For further reference to using the Graph and FQL API&#8217;s you can refer to <a href="http://developers.facebook.com/docs/reference/api/">Facebook&#8217;s API</a> documentation.  As I am sure you are used to using the great documentation provided by Apple for developing your iOS applications, but you may find the Facebook API documentation to not be so great.</p>
<p>In order to integrate Facebook into your app you will need to create an application on <a href="http://www.facebook.com/developers">www.facebook.com/developers</a>.  After creating the application you will be provided with keys needed for accessing the API&#8217;s. There are some nice features to integrating Facebook into your application such as seeing how many people &#8220;Like&#8221; your application, and statistics about the usage of your application.</p>
<p>In this tutorial we will be creating a simple Facebook news feed posting application with the following features/functionality.</p>
<ul>
<li>Facebook API / SDK Request Wrapper</li>
<li>News feed post class</li>
<li>Simple UI to test the code</li>
</ul>
<p>Getting Started:</p>
<p>Before you can begin writing code there are a few setup steps you will need to perform to setup access to the Facebook API.</p>
<p>First you will need to logon to <a href="http://www.facebook.com/developers">www.facebook.com/developers</a>, and create an application.  For this tutorial you can use the keys provided in the sample project. Once you have created an application the developer page Facebook will provide you with the keys needed .</p>
<p>Secondly, you will need to download the source for the Facebook SDK <a href="https://github.com/facebook/facebook-ios-sdk">https://github.com/facebook/facebook-ios-sdk</a>.  You may also pull the SDK source out of the sample project provided.  Included with the Facebook SDK are JSON parsing libraries, the Facebook SDK uses these libraries to parse the incoming data from their servers. Once this is done you can start to code!</p>
<p>Within your xCode project you will need to include the Facebook SDK folder and the JSON parsing Library folder.<br />
<img src="/wp-content/uploads/2011/03/Facebook-External-Libraries.png" alt="" /></p>
<p>Creating FBRequestWrapper class:<br />
This class can be used to make GET and POST requests to the API.  I like using a singleton class for this, obviously whilst writing Friended we have to make many requests and this proved to be the best method for what we needed.  This is a singleton class that will handle all the requests for accessing the Facebook API.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Facebook.h&quot;</span>
&nbsp;
<span style="color: #6e371a;">#define FB_APP_ID @&quot;197366800287642&quot;</span>
<span style="color: #6e371a;">#define FB_API_KEY @&quot;3269fff9ef3b6fc13255e670ebb44c4d&quot;</span>
<span style="color: #6e371a;">#define FB_APP_SECRET @&quot;d038b12cc8632865952f69722fe26393&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> FBRequestWrapper <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>
<span style="color: #002200;">&#123;</span>
	Facebook <span style="color: #002200;">*</span>facebook;
	<span style="color: #a61390;">BOOL</span> isLoggedIn;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">BOOL</span> isLoggedIn;
&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> defaultManager;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> setIsLoggedIn<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> _loggedIn;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> FBSessionBegin<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> FBLogout;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> getFBRequestWithGraphPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _path andDelegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> sendFBRequestWithGraphPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _path params<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params andDelegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate;
&nbsp;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>In the FBRequestWrapper.h file you will need to define the keys provided when you created your application on the Facebook Developer site.</p>
<p>FB_APP_ID, FB_API_KEY, FB_APP_SECRET</p>
<p>We will be creating two class variables, one for the Facebook SDK class, and a logged in Boolean variable which holds the status of being logged in.</p>
<p>Moving on to the Implementation of the FBRequestWrapper.  FBSessionBegin this method is being used to instantiate the facebook object if it already has not, also will be connect the application to the Facebook SDK.  Within this method we pull out the stored values for the accessToken and expiration date.  These values are stored in NSUserDefaults once a user has logged in, we store these so that we will not have to repeatedly need to request these values from Facebook.</p>
<p>Once we have that setup, we need to specify an Array of the permissions this application will be requesting.  For this application we only need the &#8220;publish_stream&#8221; permission, for more information on other permissions you can refer to the Facebook API Reference.  Once we have created this array with the requested permissions we call the facebook authorize method.  We are specifying the delegate passed to this wrapper class as the call back for a success or failure to login, this will be discussed in detail later.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> FBSessionBegin<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>facebook <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		facebook <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Facebook alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>token <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span> objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;access_token&quot;</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span><span style="color: #a61390;">exp</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSUserDefaults</span> standardUserDefaults<span style="color: #002200;">&#93;</span> objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;exp_date&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>token <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;</span>amp;<span style="color: #002200;">&amp;</span>amp; <span style="color: #a61390;">exp</span> <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;</span>amp;<span style="color: #002200;">&amp;</span>amp; <span style="color: #002200;">&#91;</span>token length<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&amp;</span>gt; <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			isLoggedIn <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;
			facebook.accessToken <span style="color: #002200;">=</span> token;
            facebook.expirationDate <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> distantFuture<span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#125;</span> 
&nbsp;
		<span style="color: #002200;">&#91;</span>facebook retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span> permissions <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span>
							 <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;publish_stream&quot;</span>,
							 <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//if no session is available login</span>
	<span style="color: #002200;">&#91;</span>facebook authorize<span style="color: #002200;">:</span>FB_APP_ID permissions<span style="color: #002200;">:</span>permissions delegate<span style="color: #002200;">:</span>_delegate<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Next we need to create the method that will be passing the POST requests to the Facebook API.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Used for publishing</span>
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> sendFBRequestWithGraphPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _path params<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableDictionary</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _params andDelegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>_delegate <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>
		_delegate <span style="color: #002200;">=</span> self;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>_params <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;</span>amp;<span style="color: #002200;">&amp;</span>amp; _path <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> setNetworkActivityIndicatorVisible<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
		<span style="color: #002200;">&#91;</span>facebook requestWithGraphPath<span style="color: #002200;">:</span>_path andParams<span style="color: #002200;">:</span>_params andHttpMethod<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;POST&quot;</span> andDelegate<span style="color: #002200;">:</span>_delegate<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>In this method we are simply doing some validation, and sending the POST request to Facebook. The delegate passed to this method will be receiving the Pass/Fail response.  This method will be used for all POST requests in the future. Other methods that are in the sample project are not contained in the scope of this tutorial.</p>
<p>Next we need to create the FBFeedPost class which will handle posting three different types of items to the users news feed.  We will start by creating an enumeration to handle the 3 different types of posts that we will be explaining. We need three different post types, FBPostTypeStatus, FBPostTypePhoto, FBPostTypeLink.  Once the enumeration has been completed we will create 5 properties in the class to be used, and create a delegate for a callback with the result of posting to Facebook.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;FBRequestWrapper.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> FBFeedPostDelegate;
&nbsp;
<span style="color: #a61390;">typedef</span> <span style="color: #a61390;">enum</span> <span style="color: #002200;">&#123;</span>
  FBPostTypeStatus <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>,
  FBPostTypePhoto <span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span>,
  FBPostTypeLink <span style="color: #002200;">=</span> <span style="color: #2400d9;">2</span>
<span style="color: #002200;">&#125;</span> FBPostType;
&nbsp;
<span style="color: #a61390;">@interface</span> FBFeedPost <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>message;
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>caption;
	UIImage <span style="color: #002200;">*</span>image;
	FBPostType postType;
&nbsp;
	<span style="color: #a61390;">id</span>  delegate;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> FBPostType postType;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>url;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>message;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>caption;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> UIImage <span style="color: #002200;">*</span>image;
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">id</span>  delegate;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithLinkPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _url caption<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _caption;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPostMessage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _message;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPhoto<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _image name<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _name;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> publishPostWithDelegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate;
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> FBFeedPostDelegate
@required
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> failedToPublishPost<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBFeedPost<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _post;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> finishedPublishingPost<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBFeedPost<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _post;
<span style="color: #a61390;">@end</span></pre></td></tr></table></div>

<p>This class will be specifically be used for posting three different types of posts to your news feed.  In this case I have created three different initialization methods for the different posts.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithLinkPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _url caption<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _caption <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		postType <span style="color: #002200;">=</span> FBPostTypeLink;
		url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_url retain<span style="color: #002200;">&#93;</span>;
		caption <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_caption retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPostMessage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _message <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		postType <span style="color: #002200;">=</span> FBPostTypeStatus;
		message <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_message retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> initWithPhoto<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _image name<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _name <span style="color: #002200;">&#123;</span>
	self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		postType <span style="color: #002200;">=</span> FBPostTypePhoto;
		image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_image retain<span style="color: #002200;">&#93;</span>;
		caption <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>_image retain<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>The meat and potatoes of this class is contained within the publishPostWithDelegate method.</p>
<p>We pass in the delegate that will be handling the response we receive from the FBRequrestWrapper class. From there we will be checking whether we are currently logged in to Facebook, if not make the Request to login via the FBRequestWrapper.  If this is the first time the application is being ran for the users login they will be prompted to allow access to post to the users feed.  Once the user has allowed access for the application to access the users feed they will no longer be prompted again to allow access.</p>
<p>Once logged in, we determine which post type we will be sending to the users feed.  Each of the three different post types require specific parameters to be passed to Facebook via a dictionary.</p>
<p>Once the proper parameters have been set simply call:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> sendFBRequestWithGraphPath<span style="color: #002200;">:</span>graphPath params<span style="color: #002200;">:</span>params andDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Whilst making the request we will be passing the delegate of the FBRequestWrapper as self, not the previously passed in delegate for the FBFeedPost class. We do this in order to handle deallocating the FBFeedPost instance after a failure or success message has been passed back from the Facebook API.</p>
<p>Within the FBFeedPost class we are implementing the Facebook SDK call back methods.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> publishPostWithDelegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> _delegate <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">//store the delegate incase the user needs to login</span>
	self.delegate <span style="color: #002200;">=</span> _delegate;
&nbsp;
	<span style="color: #11740a; font-style: italic;">// if the user is not currently logged in begin the session</span>
	<span style="color: #a61390;">BOOL</span> loggedIn <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> isLoggedIn<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>loggedIn<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> FBSessionBegin<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>params <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
		<span style="color: #11740a; font-style: italic;">//Need to provide POST parameters to the Facebook SDK for the specific post type</span>
		<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>graphPath <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;me/feed&quot;</span>;
&nbsp;
		<span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>postType<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
			<span style="color: #a61390;">case</span> FBPostTypeLink<span style="color: #002200;">:</span>
			<span style="color: #002200;">&#123;</span>
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;link&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;type&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span>self.url forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;link&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span>self.caption forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;description&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #a61390;">break</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">case</span> FBPostTypeStatus<span style="color: #002200;">:</span>
			<span style="color: #002200;">&#123;</span>
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;status&quot;</span> forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;type&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span>self.message forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #a61390;">break</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">case</span> FBPostTypePhoto<span style="color: #002200;">:</span>
			<span style="color: #002200;">&#123;</span>
				graphPath <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;me/photos&quot;</span>;
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span>self.image forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;source&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #002200;">&#91;</span>params setObject<span style="color: #002200;">:</span>self.caption forKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;message&quot;</span><span style="color: #002200;">&#93;</span>;
				<span style="color: #a61390;">break</span>;
			<span style="color: #002200;">&#125;</span>
			<span style="color: #a61390;">default</span><span style="color: #002200;">:</span>
				<span style="color: #a61390;">break</span>;
		<span style="color: #002200;">&#125;</span>
&nbsp;
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> sendFBRequestWithGraphPath<span style="color: #002200;">:</span>graphPath params<span style="color: #002200;">:</span>params andDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark FacebookSessionDelegate</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>fbDidLogin <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> setIsLoggedIn<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//after the user is logged in try to publish the post</span>
	<span style="color: #002200;">&#91;</span>self publishPostWithDelegate<span style="color: #002200;">:</span>self.delegate<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>fbDidNotLogin<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>cancelled <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBRequestWrapper defaultManager<span style="color: #002200;">&#93;</span> setIsLoggedIn<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark FBRequestDelegate</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>request<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request didFailWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> setNetworkActivityIndicatorVisible<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ResponseFailed: %@&quot;</span>, error<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self.delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>failedToPublishPost<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#91;</span>self.delegate failedToPublishPost<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>request<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBRequest <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request didLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>result <span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> setNetworkActivityIndicatorVisible<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Parsed Response: %@&quot;</span>, result<span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self.delegate respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>finishedPublishingPost<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
		<span style="color: #002200;">&#91;</span>self.delegate finishedPublishingPost<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Once either Facebook has returned a success message or failure we will call the FBFeedPost&#8217;s corresponding delegate methods with a parameter of self so we can handle the memory management necessary after we have finished posting to the users feed.</p>
<p>Now that this class is implemented we can easily use this class! Within the sample project you can see all three post type examples.  To Post a status to your feed, all you need to implement are the FBFeedPost Delegate methods and creating the request.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>IBAction<span style="color: #002200;">&#41;</span> btnPostPress<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> sender <span style="color: #002200;">&#123;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>self.txtView resignFirstResponder<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//we will release this object when it is finished posting</span>
	FBFeedPost <span style="color: #002200;">*</span>post <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FBFeedPost alloc<span style="color: #002200;">&#93;</span> initWithPostMessage<span style="color: #002200;">:</span>self.txtView.text<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>post publishPostWithDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
	IFNNotificationDisplay <span style="color: #002200;">*</span>display <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>IFNNotificationDisplay alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	display.type <span style="color: #002200;">=</span> NotificationDisplayTypeLoading;
	display.tag <span style="color: #002200;">=</span> NOTIFICATION_DISPLAY_TAG;
	<span style="color: #002200;">&#91;</span>display setNotificationText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Posting Status...&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display displayInView<span style="color: #002200;">:</span>self.view atCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>self.view.center.x, self.view.center.y<span style="color: #002200;">-</span><span style="color: #2400d9;">100.0</span><span style="color: #002200;">&#41;</span> withInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #6e371a;">#pragma mark -</span>
<span style="color: #6e371a;">#pragma mark FBFeedPostDelegate</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> failedToPublishPost<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBFeedPost<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _post <span style="color: #002200;">&#123;</span>
&nbsp;
	UIView <span style="color: #002200;">*</span>dv <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.view viewWithTag<span style="color: #002200;">:</span>NOTIFICATION_DISPLAY_TAG<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>dv removeFromSuperview<span style="color: #002200;">&#93;</span>;
&nbsp;
	IFNNotificationDisplay <span style="color: #002200;">*</span>display <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>IFNNotificationDisplay alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	display.type <span style="color: #002200;">=</span> NotificationDisplayTypeText;
	<span style="color: #002200;">&#91;</span>display setNotificationText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Failed To Post&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display displayInView<span style="color: #002200;">:</span>self.view atCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>self.view.center.x, self.view.center.y<span style="color: #002200;">-</span><span style="color: #2400d9;">100.0</span><span style="color: #002200;">&#41;</span> withInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">1.5</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//release the alloc'd post</span>
	<span style="color: #002200;">&#91;</span>_post release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> finishedPublishingPost<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FBFeedPost<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> _post <span style="color: #002200;">&#123;</span>
&nbsp;
	UIView <span style="color: #002200;">*</span>dv <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.view viewWithTag<span style="color: #002200;">:</span>NOTIFICATION_DISPLAY_TAG<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>dv removeFromSuperview<span style="color: #002200;">&#93;</span>;
&nbsp;
	IFNNotificationDisplay <span style="color: #002200;">*</span>display <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>IFNNotificationDisplay alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	display.type <span style="color: #002200;">=</span> NotificationDisplayTypeText;
	<span style="color: #002200;">&#91;</span>display setNotificationText<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Finished Posting&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display displayInView<span style="color: #002200;">:</span>self.view atCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span>self.view.center.x, self.view.center.y<span style="color: #002200;">-</span><span style="color: #2400d9;">100.0</span><span style="color: #002200;">&#41;</span> withInterval<span style="color: #002200;">:</span><span style="color: #2400d9;">1.5</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>display release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #11740a; font-style: italic;">//release the alloc'd post</span>
	<span style="color: #002200;">&#91;</span>_post release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Posting to Facebook is easy as that! You can find all the code from this tutorial in the <a href="https://github.com/ayanok/Andy-Yanok---Public-Sample-Code">sample project </a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2011/03/28/facebook-sdk-posting-to-user-news-feed/feed/</wfw:commentRss>
		<slash:comments>72</slash:comments>
		</item>
	</channel>
</rss>
