App crashing with exception: -[NSConcreteMutableData _fastCharacterContents]


I am trying to share data with facebook. I am able to share data except image stored locally in iPhone memory. But when I try to share image stored locally with parameter @"source" my app gets terminated with error "[NSConcreteMutableData _fastCharacterContents]".

For sharing a local image I am converting it into NSData as required by @"source" parameter.

NSData *data = [NSData dataWithContentsOfURL:localUrl]; __block ACAccount *facebookAccount = nil; ACAccountType *facebookAccountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; // Specify App ID and permissions NSDictionary *options = @{ ACFacebookAppIdKey: @"xxxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"email"], ACFacebookAudienceKey: ACFacebookAudienceEveryone }; // basic read permissions [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options completion:^(BOOL granted, NSError *e) { if (granted) { // Now that you have publish permissions execute the request NSDictionary *options2 = @{ ACFacebookAppIdKey: @"xxxxxxxxxxxxxx", ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions"], ACFacebookAudienceKey: ACFacebookAudienceFriends }; [self.accountStore requestAccessToAccountsWithType:facebookAccountType options:options2 completion:^(BOOL granted, NSError *error) { if (granted) { NSArray *accounts = [self.accountStore accountsWithAccountType:facebookAccountType]; facebookAccount = [accounts lastObject]; /*NSDictionary *parameters = @{@"message": @"This is a test", @"name": @"Sharing Tutorial", @"caption": @"Build great social apps and get more installs.", @"description": @"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"link": @"https://developers.facebook.com/docs/ios/share/", @"source":data};*/ NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"My hat image", @"message", data, @"source", nil]; NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"]; SLRequest *feedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters]; NSLog(@"AnythingHere?"); [feedRequest setAccount:facebookAccount]; [feedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { // Handle response NSLog(@"%@%@", error,urlResponse); NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil]; NSLog(@"Facebook Response : %@",response); }]; } else { NSLog(@"Access denied 2"); NSLog(@"%@", [error description]); } }]; } else { NSLog(@"Error: %@", [e description]); NSLog(@"Access denied"); } }];

What can be the reason behind this error?


This is just an educated guess because I've never used the Social framework, but it's too long for a comment.

Judging by this <a href="https://stackoverflow.com/a/12869455/457406" rel="nofollow">answer</a> I would say that you are using SLRequest wrong. I'm pretty sure that the exception comes from your data object which is interpreted as a NSString (or NSURL).<br /> Maybe you should use <a href="https://developer.apple.com/library/ios/documentation/Social/Reference/SLRequest_Class/Reference/Reference.html#//apple_ref/occ/instm/SLRequest/addMultipartData:withName:type:filename:" rel="nofollow">addMultipartData:withName:type:filename:</a> to attach your photo to the request.

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"My hat image", @"message", nil]; NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"]; SLRequest *feedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:parameters]; [feedRequest addMultipartData:data withName:@"source" type:@"multipart/form-data" filename:@"Test Image"];

which is basically the same code as <a href="https://stackoverflow.com/a/13372363/457406" rel="nofollow">another answer</a>


please recheck your parameters formation.

and convert your image in following formate(Base64)

NSData *rep = UIImagePNGRepresentation(img); NSLog(@"Rep: %@", rep); NSString *base64 = [rep encodeBase64]; NSLog(@"Base 64 is a %@", NSStringFromClass([base64 class])); self.somestring = [@"hardcodedstring" stringByAppendingString:base64]; //encodeBase64 encodes it to base64


  • Unexpected end of input Jquery
  • Facebook background share from android app (facebook sdk 3.x)
  • Post on Facebook profile/page timeline using Facebook Graph API v3.1 PHP SDK
  • How to create a non-expiring Facebook page token as described in the Removal of offline_access permi
  • Sending Request 2.0 app-generated request to other than “/me”
  • Facebook return com.facebook.sdk error 5 during Friend Wall Post
  • Photo not visible for my friends but it's on my timeline
  • How to post in Facebook with @mention ability using stream.publish?
  • How to upload video to Vimeo through their api?
  • How to sort results based on join table in Rails?
  • Creating account using accounts-password in meteor
  • How to check the permission whether a friend allow me to post on his wall or not using php sdk
  • Check if a UITableViewCell is completely visible
  • WEBHDFS REST API to copy/move files from windows server/local folder/desktop to HDFS
  • Posting to Facebook Page through API as the page (with admin rights)
  • Sharepoint change Content Type in Sharepoint Designer using workflow
  • Google API - Redirect URI mismatch error
  • Grails 3 - How to publish to Artifactory
  • Why is my SqlPackage DeployReport returning an empty report?
  • How do display a UIAlertView from a block on iOS?
  • Meteor: Block access to application if user's email is not verified
  • Apply a gradle plugin with a common configuration to all projects
  • LINQ to Entities does not recognize the method 'System.String ToString()' method, and this
  • Mocking Non-Standard Events in F# Foq
  • NSMutableArray instance used in a block
  • Magento site down due to mysql error General error: 1030 Got error -1 from storage engine
  • Security issues with PHP's Readfile method
  • Saving Changes After In-App Purchase Has Been Purchased
  • onBackPressed() not being executed
  • Row Count Is Returning the incorrect number using RaptureXML
  • Is there any way to access browser form field suggestions from JavaScript?
  • How would I use PHP exceptions to define a redirect?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Join two tables and save into third-sql
  • Symfony2: How to get request parameter
  • Delete MySQLi record without showing the id in the URL
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • Getting Messege Twice Using IMvxMessenger
  • Programmatically clearing map cache