0
votes

I have a View Controller that implements some delegate methods from my facebook helper. When tapping on some icon (like icon), my app switches to facebook mobile web to login. After that, it switches back my app, however, the app requires more permissions for writing so facebook mobile web (safari) once again switches. I press OK and the action done. However, the delegate methods in my View Controller not called. I debug and can see at that time the facebook action happens, the variable "delegate" is nil. My View Controller has something special. Every time returning back from background, it presents another view controller (for sponsor screen). The displaying duration takes around 3s then the Sponsor screen disappears.
How can I make the delegate methods called?
In my view controller
[FacebookHelper sharedInstance].fbDelegate = self; [[FacebookHelper sharedInstance] likeCommentFacebook:!isLike withCommentID:message.messageID];
In my facebook helper:
`- (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];
                }
            }
        }];
    }
}

}`

and in callback method


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

1
We cannot help without seeing code.trojanfoe
It's difficult to post code because the flow goes through many methods and blocks. One more thing that I detects is that if I use NSNotificationCenter then hooks the notification with a method in my ViewController, the method can receive the returned signal.lenhhoxung
Not sure what we can do then. It's pure guesswork why the delegate is going nil.trojanfoe
@trojanfoe: Please look at the code abovelenhhoxung

1 Answers

0
votes

have you set the delegate to self in that ViewController and also have mentioned/implemented the delegate in .h file of yourViewController as below.

yourViewController.h

@interface yourViewController : UIViewController<yourDelegate>

yourViewController.m

[yourComponent setYourDelegate:self];