IPhone: unrecognized selector sent to instance exception when posting stream to Facebook

I wrote the following code to log in to my Facebook account, and then posted a comment on the user's facebook wall. It works great and posts everything mentioned below on the Facebook wall, but that throws the following exception and terminating the application is abnormal. I scratched my head, but could not find anything wrong. Can someone tell me what is wrong in my code? FYI I combined this code with link1 and link2 Thank you!

An exception:

-[NSConcreteMutableData objectForKey:]: unrecognized selector sent to instance 0x34a560 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData objectForKey:]: unrecognized selector sent to instance 0x34a560' 

Enter Facebook code:

 - (void)login { NSLog(@"Logging into Facebook..."); UniversalAppAppDelegate *delegate = (UniversalAppAppDelegate *) [[UIApplication sharedApplication] delegate]; NSArray* requiredPermissions = [NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil]; if (![[delegate facebook] isSessionValid]) { [delegate facebook].sessionDelegate = self; [[delegate facebook] authorize:requiredPermissions]; } } 

Placement on the wall:

 - (void)postCommentToFacebookWall:(NSString*)comment { UniversalAppAppDelegate *delegate = (UniversalAppAppDelegate *) [[UIApplication sharedApplication] delegate]; NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: kAppId, @"api_key", @"This is test message from my iPhone App",@"message", nil]; [[delegate facebook] requestWithMethodName:@"stream.publish" andParams:params andHttpMethod:@"POST" andDelegate:self]; } 
0
source share
2 answers

I did not find any problems with this code. But it looks like some kind of NSMutableData object is trying to be used instead of NSDictionary. that is, NSData does not have an objectForKey: method. Perhaps this happens elsewhere in the application.

Have callback methods been implemented? You specify yourself as a delegate in "requestWithMethodName:".

0
source

I had this problem until I realized that I was looking for the result:

  • (void) request: (FBRequest *) request didLoad: (id) result

This method is called upon publication and registration / authorization. As part of my authorization, I was looking for objects / keys, but when posting on the wall, the result was returned as NSMutableData, not NSMUtableDict. Just make sure you are not looking for clues here ...

+1
source

Source: https://habr.com/ru/post/1308463/


All Articles