I have wrote following code to logged into Facebook account followed by posting comment on user's facebook wall. It's working fine and posting everything mentioned below on Facebook wall but it throwing following exception and termination application abnormally. I scratched my head a lot but couldn't find anything wrong. Could anyone please tell me what's wrong in my code? FYI I have combined this code from link1 and link2Thanks!
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'
Login into 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];
}
}
Posting on 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];
}
I've not found any problems with this code. But looks like some NSMutableData object tries to be used instead NSDictionary. i.e. NSData has no "objectForKey:" method. May be this occurs in another place of application.
Did you implement callbacks methods? You set yourself as delegate in "requestWithMethodName:".
I had this problem until i realised that I was searching the result in:
This method gets called when posting and logging in/authorising. As part of my authorisation I was searching for objects/keys but when posting to the wall the result comes back as NSMutableData and not NSMUtableDict. Just make sure you aren't searching for keys in here ...