iOS:Facebook评论插件手机不断重新加载 [英] iOS: Facebook Comments Plugin mobile keeps reloading

查看:173
本文介绍了iOS:Facebook评论插件手机不断重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在尝试将Facebook社交插件集成到iOS中的自定义UIWebView中以评论网页。我已经添加了Like按钮以及Comments插件。以下是加载到网络视图中的HTML代码:

 < html> 
< 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;
fjs.parentNode.insertBefore(js,fjs);
}(document,'script','facebook-jssdk'));< / script> data-width =240data-width =数据显示-面= 假 >< / DIV>
< div class =fb-commentsdata-href =http://www.heretheweb.comdata-num-posts =5data-width =470> DIV>
< body>
< / html>

星期一的第一个实现在四个平台(两个模拟器(iOS 4和iOS 5))都是成功的, iPhone 3G iOS4和iPhone 4 iOS 5.
星期二,我一直在开发这个,最后我的自定义UIWebView在前三个没有问题。但是在iPhone 4(iOS 5)上,网页视图一遍又一遍地重新加载相同的网页,导致评论框永远不会出现。这个URL是这样的:



https://m.facebook.com /plugins/comments.php?channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D4%23cb%3Df28c738848%26origin%3Dhttp%253A%252F%252Fwww.heretheweb.com %252Ff3fdf142e8%26domain%3Dwww.heretheweb.com%26relation%3Dparent.parent&安培; HREF = HTTP%3A%2F%2Fwww.heretheweb.com&安培;语言环境= EN_US&安培;流动=真安培; numposts = 5&安培; SDK =乔伊&安培;宽度= 470



我不知道我在做什么错了,我已经清理了uiWebView委托方法,我已经检查了断点所有的方法我可以覆盖没有...网页在开头加载,然后循环尝试加载上述URL ...

解决方案

好吧解决了
对于一些奇怪而奇怪的原因,有时在iPhone 4(而不是模拟器,iPhone 3G或iPad 2)中加载评论web部分时,会尝试重新加载一次(Cache-Control头设置为max -age = 0,所以它一直强制重新加载)



解决方法是检查UIWebViewNavigationType,如果它等于UIWebViewNavigationTypeReload,shouldStartLoadWithRequest:返回NO。



真的很棘手¬¬


Recently I have been trying to integrate Facebook Social Plugins into a custom UIWebView in iOS for commenting a webpage. I have added the Like Button as well as the Comments plugin. Here is the HTML code I load into the web view:

  <html>
    <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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://www.heretheweb.com" data-send="false" data-layout="button_count" data-width="240" data-show-faces="false"></div>
<div class="fb-comments" data-href="http://www.heretheweb.com" data-num-posts="5" data-width="470"></div>
<body>
</html>

The first implementation on Monday was sucessfull in 4 platforms, both simulators (iOS 4 and iOS 5), iPhone 3G iOS4 and iPhone 4 iOS 5. On Tuesday, I kept developing this and I ended up with my custom UIWebView working with no problems in the first three. But on iPhone 4 (iOS 5) the web view kept reloading the same web page over and over again, resulting in the comment box never appearing. That URL is this:

https://m.facebook.com/plugins/comments.php?channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D4%23cb%3Df28c738848%26origin%3Dhttp%253A%252F%252Fwww.heretheweb.com%252Ff3fdf142e8%26domain%3Dwww.heretheweb.com%26relation%3Dparent.parent&href=http%3A%2F%2Fwww.heretheweb.com&locale=en_US&mobile=true&numposts=5&sdk=joey&width=470

I don't know what I am doing wrong really, I have cleaned the uiWebView delegate methods, I have check with breakpoints ALL the methods I could override. Nothing... The webpage gets loaded at the beginning, and then it loops trying to load the above URL...

解决方案

Ok... solved. For some strange and weird reason, sometimes when loading the comments web part ONLY in iPhone 4 (not simulator, iPhone 3G or iPad 2) it tries to reload once and once again (the Cache-Control header is set to max-age=0, so it keeps forcing the reload)

The solution was to check the UIWebViewNavigationType, if it's equal to UIWebViewNavigationTypeReload, shouldStartLoadWithRequest: returns NO.

It was REALLY tricky ¬¬

这篇关于iOS:Facebook评论插件手机不断重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆