我正在尝试将facebook评论框添加到我的基于网络的应用程序中,但是当我在手机上安装时它不显示。是否有一些特殊的插件或方法可以让facebook评论插件与phonegap和/或离子一起使用?我目前在配置中有这个插件:
<gap:plugin name="com.phonegap.plugins.facebookconnect" version="0.9.0">
答案 0 :(得分:1)
我设法用iframe做了。 我用https://github.com/davidjbradshaw/iframe-resizer
解决了调整大小问题登录时我必须更改本机代码。
iOS:MainViewController.m
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if (![url isFileURL] && (navigationType == UIWebViewNavigationTypeLinkClicked))
{ //this is for loading links in external browser
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
} else if ([[url absoluteString] containsString:@"m.facebook.com"] && [[url absoluteString] containsString:@"login"]) {
NSString *forceInAppBrowserJS = [NSString stringWithFormat:
@"var loginWindow = cordova.InAppBrowser.open('%@', '_blank', 'location=yes');\n\
loginWindow.addEventListener('exit', function(){\n\
window.fbIframe.src = window.fbIframe.src;\n\
});", url]; //reload the iframe after login, you have to assign the iframe in js
[theWebView stringByEvaluatingJavaScriptFromString: forceInAppBrowserJS];
return NO;
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
Android:CordovaWebViewClient.java
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains("file://")) {
if (url.contains("m.facebook.com") && url.contains("login")) {
String forceInAppBrowserJS = String.format("var loginWindow = cordova.InAppBrowser.open('%s', '_blank', 'location=yes,hardwareback=yes'); loginWindow.addEventListener('exit', function(){window.fbIframe.src = window.fbIframe.src;});", url);
view.evaluateJavascript(forceInAppBrowserJS, null);
return true;
}
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(browserIntent); //open link in external browser
return true;
}
return helper.shouldOverrideUrlLoading(view, url);
}
答案 1 :(得分:0)
到目前为止,我找到的最佳解决方案是从iframe内部调用评论框。到目前为止,这种方法的唯一问题是登录并设置iframe高度。我还在研究解决方案