Facebook 参数问题导致应用程序终止 - iPhone

发布于 2024-11-29 22:28:19 字数 1622 浏览 0 评论 0原文

我尝试从 iPhone 应用程序向 Facebook 发帖,但不起作用。

这就是我正在做的:

if (![_facebook isSessionValid])
    {
        NSArray *permissions =  [NSArray arrayWithObjects:
                                 @"read_stream", @"publish_stream", @"offline_access",nil];

        [facebook authorize:permissions delegate:self];
    }

    NSMutableDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"User Prompt Message",  @"user_message_prompt",
                            @"http://www.mywebsite.com/", @"link",
                            @"http://mywebsite.com/wp-content/uploads/2011/05/iTunesArtwork.png", @"picture",
                            nil];


    [facebook requestWithGraphPath:@"me/feed"
                         andParams:params  
                     andHttpMethod:@"POST" 
                       andDelegate:self];

我也尝试过

[self.facebook 对话框:@"feed" andParams:params andDelegate:self];

但无论哪种情况,我的应用程序都会被终止

  • (FBRequest*)openUrl:(NSString *)url 参数:(NSMutableDictionary *)参数 httpMethod:(NSString *)httpMethod 委托:(id)委托

或在

  • (void)对话框:(NSString *)操作 andParams:(NSMutableDictionary *)params andDelegate:(id )委托

取决于我使用此日志调用的方法:

* 由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'-[__NSCFDictionary setObject:forKey:]:发送到不可变对象的变异方法'

这对我来说没有意义,因为正在使用的字典是可变的。

我做错了什么吗?任何帮助将不胜感激。

I am trying to post to Facebook from my iPhone app and it just doesn't work.

This is what I am doing:

if (![_facebook isSessionValid])
    {
        NSArray *permissions =  [NSArray arrayWithObjects:
                                 @"read_stream", @"publish_stream", @"offline_access",nil];

        [facebook authorize:permissions delegate:self];
    }

    NSMutableDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"User Prompt Message",  @"user_message_prompt",
                            @"http://www.mywebsite.com/", @"link",
                            @"http://mywebsite.com/wp-content/uploads/2011/05/iTunesArtwork.png", @"picture",
                            nil];


    [facebook requestWithGraphPath:@"me/feed"
                         andParams:params  
                     andHttpMethod:@"POST" 
                       andDelegate:self];

I also tried

[self.facebook dialog:@"feed" andParams:params andDelegate:self];

but in either case my app is getting terminated either in

  • (FBRequest*)openUrl:(NSString *)url
    params:(NSMutableDictionary *)params
    httpMethod:(NSString *)httpMethod
    delegate:(id)delegate

or in

  • (void)dialog:(NSString *)action
    andParams:(NSMutableDictionary *)params andDelegate:(id
    )delegate

depending on which method I call with this log:

* Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '-[__NSCFDictionary
setObject:forKey:]: mutating method sent to immutable object'

It doesn't make sense to me because the dictionaries being used are mutable.

Am I doing something wrong? Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-12-06 22:28:20

这对我来说没有意义,因为所使用的字典是可变的。

不,他们不是。尽管您将返回的对象分配给 NSMutableDictionary 变量,但您还是在此处创建 NSDictionary

NSMutableDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                                    ^
                                  Here!
                              @"User Prompt Message",  @"user_message_prompt",
                              @"http://www.mywebsite.com/", @"link",
                              @"http://mywebsite.com/wp-content/uploads/2011/05/iTunesArtwork.png", @"picture",
                              nil];

这应该是:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:...];

这可能是崩溃的原因:

  • 由于未捕获的异常而终止应用程序
    'NSInternalInconsistencyException',原因:'-[__NSCFDictionary
    setObject:forKey:]: 发送到不可变对象的变异方法'

,因为 Facebook API 需要一个可变字典:

- (FBRequest*)requestWithGraphPath:(NSString *)graphPath
                         andParams:(NSMutableDictionary *)params
                                            ^
                                 It needs to be mutable!
                     andHttpMethod:(NSString *)httpMethod
                       andDelegate:(id <FBRequestDelegate>)delegate;

It doesn't make sense to me because the dictionaries being used are mutable.

No, they are not. Despite that you are assigning the returned object to a NSMutableDictionary variable, you are creating a NSDictionary here:

NSMutableDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
                                    ^
                                  Here!
                              @"User Prompt Message",  @"user_message_prompt",
                              @"http://www.mywebsite.com/", @"link",
                              @"http://mywebsite.com/wp-content/uploads/2011/05/iTunesArtwork.png", @"picture",
                              nil];

This should be:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:...];

This is likely the cause of the crash:

  • Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: '-[__NSCFDictionary
    setObject:forKey:]: mutating method sent to immutable object'

because the Facebook API expects a mutable dictionary:

- (FBRequest*)requestWithGraphPath:(NSString *)graphPath
                         andParams:(NSMutableDictionary *)params
                                            ^
                                 It needs to be mutable!
                     andHttpMethod:(NSString *)httpMethod
                       andDelegate:(id <FBRequestDelegate>)delegate;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文