开发者

Access Facebook object delegate?

开发者 https://www.devze.com 2023-03-23 13:06 出处:网络
I\'m posting to a users Facebook wall with code similar to this: [appDelegate.facebook requestWithGraphPath:@\"me/feed\"

I'm posting to a users Facebook wall with code similar to this:

[appDelegate.facebook requestWithGraphPath:@"me/feed" 
                  andParams:params
              andHttpMethod:@"PO开发者_如何学JAVAST"
                andDelegate:self];

If I dismiss the hosting UIViewController before the request completes, I get a crash when the request does actually complete because the delegate has been dealloc'd.

Is there any way I can get around this? I don't really want to make a high level object like my appDelegate the FB delegate, this seems silly.

There's a good description of the problem I'm facing here: https://github.com/facebook/facebook-ios-sdk/issues/220


In your controller's dealloc method, set the Facebook object's delegate to nil. In your case that would look like this:

- (void)dealloc {
    appDelegate.facebook.sessionDelegate = nil;
    [super dealloc];
}

When the request completes, the delegate method will get called on the nil object, which will swallow the message silently.

This is a good habit to get into any time you set self as the delegate on any object.

0

精彩评论

暂无评论...
验证码 换一张
取 消