ios - App crashing with exception: -[NSConcreteMutableData _fastCharacterContents] -


i trying share data facebook. able share data except image stored locally in iphone memory. when try share image stored locally parameter @"source" app gets terminated error "[nsconcretemutabledata _fastcharactercontents]".

for sharing local image converting nsdata required @"source" parameter.

nsdata *data = [nsdata datawithcontentsofurl:localurl];     __block acaccount *facebookaccount = nil;      acaccounttype *facebookaccounttype = [self.accountstore accounttypewithaccounttypeidentifier:acaccounttypeidentifierfacebook];      // specify app id , 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) {              // have publish permissions execute 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 test",                                                   @"name": @"sharing tutorial",                                                   @"caption": @"build great social apps , more installs.",                                                   @"description": @"allow users share stories on facebook app using 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 reason behind error?

this educated guess because i've never used social framework, it's long comment.

judging answer using slrequest wrong. i'm pretty sure exception comes data object interpreted nsstring (or nsurl).
maybe should use addmultipartdata:withname:type:filename: attach photo 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 same code another answer


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -