0

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];
}
Community
  • 1
  • 1
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
  • 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. – SVGreg Jan 25 '12 at 12:15
  • @SVGreg: there is no other place actually! I just call postcomment method with comment argument from app-delegate. I also send comment to my database. If I comment out postcomment to facebook call then everything works fine! It's just problem when I post comment to Facebook! – Paresh Masani Jan 25 '12 at 12:20
  • 1
    Did you implement callbacks methods? You set yourself as delegate in "requestWithMethodName:". – SVGreg Jan 25 '12 at 12:25
  • Yah I do have callback methods. I am checking if there is an issue! – Paresh Masani Jan 25 '12 at 12:28
  • Also if you're not using ARC: check for zombie objects (NSZombieEnabled or Instruments). Memory management issues also can lead to this kind of problem (e.g. the memory of a NSDictionary obejct being occupied by a NSData object). – Dennis Bliefernicht Jan 25 '12 at 12:33
  • @TriPhoenix: Agree - it's can be an issue. – SVGreg Jan 25 '12 at 12:37
  • @SVGreg: Thanks buddy! The problem was in RequestDidLoad callback method. Got it sorted! – Paresh Masani Jan 25 '12 at 15:34
  • @TriPhoenix: what's ARC? – Paresh Masani Jan 25 '12 at 15:46
  • 1
    @AppleDeveloper ARC is automatic reference counting, introduced with the iOS 5 SDK (and somewhat backward-compatible to iOS 4). It eleminates many pitfalls of manual memory management by automatically inserting the appropriate retain/release calls. See for example http://www.raywenderlich.com/5677/beginning-arc-in-ios-5-part-1 – Dennis Bliefernicht Jan 25 '12 at 15:48
  • cool. Wasn't aware of it! Thanks. – Paresh Masani Jan 25 '12 at 16:07
  • Hi SVGreg, can you put your up-voted comment in answer please...I will accept it! Thanks. – Paresh Masani Jan 26 '12 at 09:20

2 Answers2

1

I had this problem until i realised that I was searching the result in:

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

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 ...

CW0007007
  • 5,681
  • 4
  • 26
  • 31
0

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:".

SVGreg
  • 2,320
  • 1
  • 13
  • 17