0

我有一个视图控制器,它从我的 facebook 助手中实现了一些委托方法。当点击某个图标(如图标)时,我的应用会切换到 facebook 移动网络进行登录。之后,它切换回我的应用程序,但是,该应用程序需要更多的写入权限,因此 facebook 移动网络(safari)再次切换。我按确定,操作完成。但是,我的视图控制器中的委托方法没有被调用。我调试并可以看到当时发生了 facebook 操作,变量“delegate”为 nil。我的视图控制器有一些特别之处。每次从后台返回时,它都会呈现另一个视图控制器(用于赞助商屏幕)。显示持续时间大约为 3 秒,然后赞助商屏幕消失。
如何调用委托方法?
在我的视图控制器中
[FacebookHelper sharedInstance].fbDelegate = self; [[FacebookHelper sharedInstance] likeCommentFacebook:!isLike withCommentID:message.messageID];
在我的 facebook 助手中:
`- (void) likeCommentFacebook:(BOOL)isLike withCommentID:(NSString *)commentID {

//- check if we are already processed by the loginCallback
if (_loginCallbackInvocation == nil) {
    //- create NSInvocation reference to this method
    NSInvocation * nsi = [WKTools invocationWithTarget:self selector:_cmd retainArguments:TRUE argumentAddresses:&isLike, &commentID];
    //- ensure user has been properly identified and process with authentication if required
    [self processLogin:nsi];
}

//- check if user session is valid
if ([[FBSession activeSession] isOpen]) {
    if (![self hasPermission:kPublishStream]) {
        NSArray *permissions = [NSArray arrayWithObjects: kPublishStream,nil];
        dispatch_async(dispatch_get_current_queue(), ^{
            [FBSession.activeSession requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) {
                NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE];
                NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil];
                //- send request
                if (isLike == YES) {
                    [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD];
                } else {
                    [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD];
                }
            }];
        });
    } else {
        NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil];
        //- send request
        if (isLike == YES) {
            [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD];
        } else {
            [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD];
        }
    }
} else {
    if ([self isSessionCachedAndLoaded]) {
        [FBSession.activeSession openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
            if (![self hasPermission:kPublishStream]) {
                [[NSUserDefaults standardUserDefaults] synchronize];
                NSArray *permissions = [NSArray arrayWithObjects: kPublishStream,nil];
                dispatch_async(dispatch_get_current_queue(), ^{
                    [FBSession.activeSession requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:^(FBSession *session, NSError *error) {
                        NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE];
                        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil];
                        DEBUGLog(@"like comment: %@",requestUrl);

                        //- send request
                        if (isLike == YES) {
                            [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD];
                        } else {
                            [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD];
                        }
                    }];
                });
            } else {
                NSString *requestUrl = [NSString stringWithFormat:@"%@%@", commentID,FB_REQUEST_LIKE];
                NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", MESSAGE_KEY, nil];
                //- send request
                if (isLike == YES) {
                    [self requestGraphAPI:requestUrl parameter:params httpMethod:POST_METHOD];
                } else {
                    [self requestGraphAPI:requestUrl parameter:params httpMethod:DELETE_METHOD];
                }
            }
        }];
    }
}

}`

并在回调方法中


if (self.fbDelegate && [self.fbDelegate respondsToSelector:@selector(likeCommentDidSuccess:)]) { [self.fbDelegate performSelector:@selector(likeCommentDidSuccess:) withObject:dictionary]; }

4

1 回答 1

0

您是否将其设置delegateselfViewController并且还提到/实现了 .h 文件中的委托,yourViewController如下所示。

你的ViewController.h

@interface yourViewController : UIViewController<yourDelegate>

你的ViewController.m

[yourComponent setYourDelegate:self];
于 2013-09-06T05:38:34.407 回答