Facebook Comment Box login issue in iOS app

567 Views Asked by At

I am using the following code to display a comment box in my iOS app, the comment box shows up fine but it always asks for the user to login to comment however the user has already logged into Facebook in my app at the starting.
I don't know how to solve it.

Here's my code:

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 280, 320.0f, 300.0f)];

if (FBSession.activeSession.isOpen) {
    NSString *html = @"\
    <!DOCTYPE html>\
    <html>\
    <head>\
    </head>\
    <body>\
    <div id=\"fb-root\"></div>\
    <script>(function(d, s, id) {\
        var js, fjs = d.getElementsByTagName(s)[0];\
        if (d.getElementById(id)) return;\
        js = d.createElement(s); js.id = id;\
        js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1&appId=211241782359485\";\
        fjs.parentNode.insertBefore(js, fjs);\
    }(document, 'script', 'facebook-jssdk'));</script>\
    <div class=\"fb-comments\" data-href=\"http://example.com\" data-width=\"470\"></div>\
    </body>\
    </html>\
    ";

    [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.example.com"]];
    webView.scrollView.scrollEnabled = TRUE;
    [self.view addSubview:webView];
1

There are 1 best solutions below

0
On

The application login is different than the login for facebook commenting. It is because facebook comment uses social plugins and open in a webview. You login once in webview which is open after clicking of sign-in button for facebook commenting. After that, you will remain login on restart of your application.