iphone graph api not working to post image in facebook
<p><strong>using this method to post the image</strong></p>

<ul>
<li><p>(void)postInAppFacebook {</p>

<p>btnForLogout.hidden=NO;
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];</p>

<p>NSData *imageData = UIImageJPEGRepresentation(imgPicture.image, 4.0);</p>

<p>UIImage *picture = [[UIImage alloc]initWithData:imageData];</p>

<p>FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:picture];</p>

<p>[variables setObject:graph_file forKey:@"file"];</p>

<p>[variables setObject:[NSString stringWithFormat:@"%@", txtComment.text] forKey:@"message"];</p>

<p><strong>[fbGraph doGraphPost:@"me/photos" withPostVars:variables];</strong></p>

<p>NSLog(@"Now log into Facebook and look at your profile &amp; photo albums...");
UIAlertView *alertForImageHasPost=[[UIAlertView alloc]initWithTitle:@"MAP IMAGE POST" message:@"SELECTED IMAGE POSTED" delegate:self cancelButtonTitle:@"CANCEL" otherButtonTitles:@"OK",nil];
[alertForImageHasPost show];
[alertForImageHasPost release];</p>

<p>[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];<br>
}</p></li>
</ul>

<p><strong>problem in this method</strong>
second time its crash but working well in simulator</p>

<ul>
<li><p>(FbGraphResponse *)doGraphPost:(NSString *)action withPostVars:(NSDictionary *)post_vars {
NSLog(@"action is %@",action);
FbGraphResponse *return_value = [[FbGraphResponse alloc] init];</p>

<p>NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@", action];</p>

<p>NSURL *url = [NSURL URLWithString:urlString];
NSString *boundary = @"----1010101010";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];</p>

<p>NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];</p>

<p>NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];</p>

<p>NSEnumerator *enumerator = [post_vars keyEnumerator];
NSString *key;
NSString *value;
NSString *content_disposition;</p>

<p>//loop through all our parameters 
while ((key = (NSString *)[enumerator nextObject])) {</p>

<pre><code>//if it's a picture (file)...we have to append the binary data
if ([key isEqualToString:@"file"]) {

    /*
     * the FbGraphFile object is smart enough to append it's data to 
     * the request automagically, regardless of the type of file being
     * attached
     */
    FbGraphFile *upload_file = (FbGraphFile *)[post_vars objectForKey:key];
    [upload_file appendDataToBody:body];

//key/value nsstring/nsstring
} else {
    value = (NSString *)[post_vars objectForKey:key];

    content_disposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key];
    [body appendData:[content_disposition dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];

}//end else

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
</code></pre>

<p>}//end while</p>

<p>//add our access token
[body appendData:[@"Content-Disposition: form-data; name=\"access_token\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[accessToken dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];</p>

<p>//button up the request body
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];</p>

<p>[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField: @"Content-Length"];</p>

<p>//quite a few lines of code to simply do the business of the HTTP connection....
NSURLResponse *response;
NSData *data_reply;
NSError *err;
<strong>//crash after this  line</strong></p>

<hr></li>
</ul>

<blockquote>
  <p>data_reply = [NSURLConnection sendSynchronousRequest:request
  returningResponse:&amp;response error:&amp;err];</p>
</blockquote>

<hr>

<pre><code>return_value.htmlResponse = (NSString *)[[NSString alloc] initWithData:data_reply encoding:NSUTF8StringEncoding];

if (err != nil) {
    return_value.error = err;
}

/*
 * return the json array.  we could parse it, but that would incur overhead 
 * some users might not want (not to mention dependencies), besides someone 
 * may want raw strings back, keep it simple.
 *
 * See:  http://code.google.com/p/json-framework for an easy json parser
 */

return return_value;
</code></pre>

<p>}</p>
