iPhone: Unrecognized selector sent to instance exception while publishing stream on Facebook

99封情书 提交于 2019-12-25 08:20:08

问题


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];
}

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/9002229/iphone-unrecognized-selector-sent-to-instance-exception-while-publishing-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!