【问题标题】:Adding facebook comment box plugin for web based phonegap app为基于 Web 的 phonegap 应用添加 facebook 评论框插件
【发布时间】:2023-03-26 21:28:01
【问题描述】:

我正在尝试将 facebook 评论框添加到我的基于 Web 的应用程序中,但是当我在手机上安装时它没有显示。是否有一些特殊的插件或方法可以让 facebook 评论插件与 phonegap 和/或 ionic 一起使用?我目前在我的配置中有这个插件:

<gap:plugin name="com.phonegap.plugins.facebookconnect" version="0.9.0">

【问题讨论】:

    标签: facebook cordova comments


    【解决方案1】:

    到目前为止,我发现的最佳解决方案是从 iframe 内部调用 cmets 框。到目前为止,这种方法的唯一问题是登录和设置 iframe 高度。我仍在研究解决方案

    【讨论】:

    • 你能帮忙写代码吗?我如何从 iframe 调用 ionic cordova 应用程序上的 facebook cmets 框?非常感谢您的帮助!
    • 也许他就是这样干的..stackoverflow.com/questions/13252259/…
    【解决方案2】:

    我也设法用 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);
    }
    

    【讨论】:

    • 当然,你必须为 Cordova 安装 InAppBrowser 插件
    猜你喜欢
    • 2012-04-09
    • 1970-01-01
    • 2011-12-18
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    相关资源
    最近更新 更多