如何使用PhoneGap的打开Twitter和Facebook应用程序? [英] How to open Twitter and Facebook app with Phonegap?

查看:259
本文介绍了如何使用PhoneGap的打开Twitter和Facebook应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有我的PhoneGap的应用程序链接到Twitter的应用程序打开一个特定的用户个人资料页面。我知道不是每个人都有自己的安装设备上,所以我想送他们到Play商店下载它,如果他们没有在Twitter的应用程序。

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.

问题是,每次我一敲我的Andr​​oid设备上的链接时,我收到了一个错误:

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.com/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');
});

的事情,我已经试过:

  • 使用微博:/// 而不是微博://
  • ?微博://用户screen_name = xerxesnoble;
  • 添加&LT获得原产地= /> 我的的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的/科尔多瓦的新版本不来与所有的插件installed-,而不是你选择,你希望你的应用程序能够访问什么。

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 $科尔多瓦插件添加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.

我安装其它插件: AppAvailability为iOS和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.com/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.com/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屋!

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