如何使用 Phonegap 打开 Twitter 和 Facebook 应用程序?

编程入门 行业动态 更新时间:2024-10-24 19:20:27
本文介绍了如何使用 Phonegap 打开 Twitter 和 Facebook 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的 PhoneGap 应用程序链接来打开 Twitter 应用程序中的特定用户个人资料页面.我知道不是每个人的设备上都安装了 Twitter 应用程序,所以我想将他们发送到 Play 商店下载,如果他们没有的话.

I am trying to have my PhoneGap application link to open a specific users profile page in the Twitter app. I know not everyone has the Twitter app installed on their device so I wanted to send them to the Play Store to download it if they didn't.

问题是每次我点击 Android 设备上的链接时都会收到错误消息:

Problem is that every time I tap the link on my Android device I receive an error:

Application Error:

net::ERR_UNKNOWN_URL_SCHEME(twitter://user?screen_name=xerxesnoble)

我的 JavaScript 如下:

My JavaScript is as follows:

//If Android

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

if (isAndroid) {

    alert('Android!');

    twitterCheck = function() {
        alert('Android!');
        var now = new Date().valueOf();

        setTimeout(function () {
            if (new Date().valueOf() - now > 100) return;
            window.open('https://play.google/store/apps/details?id=com.twitter.android', '_system', 'location=no');
        }, 50);

    window.open('twitter://user?screen_name=XerxesNoble', '_system', 'location=no');
    };
};

$('.twiterNav').click(function() {
     window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');
});

我尝试过的事情:

使用 twitter:/// 而不是 twitter://<access origin="twitter://user?screen_name=xerxesnoble"/> 添加到我的 config.xml Using twitter:/// instead of twitter:// Adding <access origin="twitter://user?screen_name=xerxesnoble" /> to my config.xml

我不知道还能尝试什么,Facebook 也没有任何效果,但现在我一次只关注一个问题.

I'm not sure what else to try, nothing is working for Facebook either but right now I'm focusing on one issue at a time.

推荐答案

问题是未安装 InAppBrowser 插件.新版本的 PhoneGap/Cordova 并未安装所有插件 - 而是您选择您希望应用程序访问的内容.

The Problem is that the InAppBrowser plugin was not installed. New versions of PhoneGap/Cordova do not come with all plugins installed- instead you choose what you want your App to have access to.

在终端 cd yourApp$cordova 插件中添加 org.apache.cordova.inappbrowser

这样做之后,它工作得很好.

After doing that, it worked perfectly.

编辑

只是想进一步了解我如何让我的 .js 来检查 twitter 是否已安装.

Just to branch out a little bit more on how I got my .js to check if twitter was installed or not.

我安装了另一个插件:适用于 iOS 和 Android 的 AppAvailability

I installed another plugin : AppAvailability for iOS and Android

然后我把我的 .js 改成这样:

Then I altered my .js to look like this:

//Twitter checker

// If Mac//

var twitterCheck = function(){

appAvailability.check('twitter://', function(availability) {
    // availability is either true or false
    if(availability) { window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
    else{window.open('https://itunes.apple/ca/app/twitter/id333903271?mt=8', '_system', 'location=no'); };
});
};

//If Android

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

if(isAndroid) {

twitterCheck = function(){    

appAvailability.check('com.twitter.android', function(availability) {
    // availability is either true or false
    if(availability) {window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
    else{window.open('https://play.google/store/apps/details?id=com.twitter.android', '_system', 'location=no');};
});
};
};

AppAvailability 插件中提供的文档也很有帮助>

The documentation provided in the AppAvailability plugin was very helpful as well>

希望这对某人有所帮助!

Hope that this helps someone!

这篇关于如何使用 Phonegap 打开 Twitter 和 Facebook 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 16:34:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/808857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   应用程序   Twitter   Phonegap   Facebook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!