iPad: Cannot load facebook page wall in UIWebview

谁说胖子不能爱 提交于 2019-11-29 12:43:55

It seems the ever capricious Facebookhas removed the permission to view the wall. I came to this conclusion as when I tried the same thing in separate project I was getting both info and photos but for wall it turned grey

So Here the solution for al those suffering or might suffer form this issue.

I am getting a dictionary in response to the post

{"id":"<imge_id>","post_id":"<post_id>"}

http://www.facebook.com/photo.php?fbid=<imge_id>

and it works like a charm.

Edit:1 Just now I figured out an issue For the pages with an age restriction, we need to authenticate which SSO doesn't supports for UIWebView inside my app.

I had to downgrade to NOT using SSO anymore. And now it works no matter what.

Just to add here you can find how to neatly downgrading to non-sso mechanism.

I think it's will help you

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([(NSMutableURLRequest *)request respondsToSelector:@selector(setValue:forHTTPHeaderField:)]) {
        [(NSMutableURLRequest *)request setValue:@" Safari/537.1" forHTTPHeaderField:@"User_Agent"];
    }
}

I hit my head against the wall on this one for a while. The same request and webview on an iPhone will pull up a facebook page, but results in a blank white page on an iPad. Changing user agent doesn't solve the problem.

I was able to hack around it by pulling down the HTML for the page I was looking for using stringWithContentsOfURL and then loading the HTML manually into the webview

You don't want to call [NSString stringWithContentsofURL from your main thread if you can help it, since it will hold up your thread until the results come back. Here is my solution for running it in the background and updating a UIWebView that I had already created and added to my subview called "facebookWebView":

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSString *rawHTML = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.facebook.com/link.to.your.page.on.facebook"] encoding:NSASCIIStringEncoding error:nil];

        dispatch_async(dispatch_get_main_queue(), ^(void) {


            [facebookWebView loadHTMLString:rawHTML baseURL:[NSURL URLWithString:@"http://www.facebook.com"]];



        });
    });

Hope this helps some people.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!