问题描述
我正在尝试使用我的 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:关键词]
发布评论