检查应用程序 facebook 工作但 twitter 和 instagram 不工作?
Check app facebook works but twitter & instagram doesnt?
我目前有一个 Ionic 应用程序可以在 InAppBrowser 中打开一个网站。
每次你移动到另一个 URL 它会检查域,如果它是 Facebook、Twitter 或 Instagram URL 它会 - 1. 检查 phone 是否有已安装应用程序 2. 如果安装了,请在应用程序中打开 URL。
我的问题是,我的 Facebook 代码可以工作,但是 Instagram 和 Twitter 不工作,有什么想法吗?提前致谢。
home.ts
//check if link is for social media
CheckSocialMediaLinks(url: string){
//get the domain
var parser = document.createElement('a');
parser.href = url;
var domain = parser.host;
if (domain === "m.facebook.com")
{
this.OpenFacebook(url);
this.navCtrl.pop();
}
else if (domain === "instagram.com")
{
this.OpenInstagram(url);
this.navCtrl.pop();
}
else if (domain === "twitter.com")
{
this.OpenTwitter(url);
this.navCtrl.pop();
}
}
OpenFacebook(url: string){
let app;
if (this.platform.is('ios')) {
app = 'fb://';
} else if (this.platform.is('android')) {
app = 'com.facebook.katana';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("fb://"+url, '_system'), //IF AVALIABLE
(no: boolean) => window.open("https://"+url, '_system')
);
}
OpenInstagram(url: string){
let app;
if (this.platform.is('ios')) {
app = 'instagram://';
} else if (this.platform.is('android')) {
app = 'com.instagram.android';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("instagram://"+url, '_system'), //Not working
(no: boolean) => window.open("https://"+url, '_system')
);
}
OpenTwitter(url: string){
let app;
if (this.platform.is('ios')) {
app = 'twitter://';
} else if (this.platform.is('android')) {
app = 'com.twitter.android';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("twitter://"+url, '_system'), //Not working
(no: boolean) => window.open("https://"+url, '_system')
);
}
编辑
做了一些调试,所有的功能都执行了,我发现它不执行或不起作用的地方是Instagram或Twitter的应用程序是否可用。 (Facebook 运行良好)
我尝试了一些变体,代码对我来说看起来不错,有什么想法吗?
Instagram - 应在应用内打开 link:
(yes: boolean) => window.open("instagram://"+url, '_system')
Twitter 应在应用内打开 link:
(yes: boolean) => window.open("twitter://"+url, '_system')
所以我想出了问题。 Twitter 和 Instagram 必须使用一种格式。
Instagram:
window.open("instagram://user?username=whateverusername", '_system')
推特:
window.open('twitter://user?screen_name=whateverusername', '_system')
我目前有一个 Ionic 应用程序可以在 InAppBrowser 中打开一个网站。
每次你移动到另一个 URL 它会检查域,如果它是 Facebook、Twitter 或 Instagram URL 它会 - 1. 检查 phone 是否有已安装应用程序 2. 如果安装了,请在应用程序中打开 URL。
我的问题是,我的 Facebook 代码可以工作,但是 Instagram 和 Twitter 不工作,有什么想法吗?提前致谢。
home.ts
//check if link is for social media
CheckSocialMediaLinks(url: string){
//get the domain
var parser = document.createElement('a');
parser.href = url;
var domain = parser.host;
if (domain === "m.facebook.com")
{
this.OpenFacebook(url);
this.navCtrl.pop();
}
else if (domain === "instagram.com")
{
this.OpenInstagram(url);
this.navCtrl.pop();
}
else if (domain === "twitter.com")
{
this.OpenTwitter(url);
this.navCtrl.pop();
}
}
OpenFacebook(url: string){
let app;
if (this.platform.is('ios')) {
app = 'fb://';
} else if (this.platform.is('android')) {
app = 'com.facebook.katana';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("fb://"+url, '_system'), //IF AVALIABLE
(no: boolean) => window.open("https://"+url, '_system')
);
}
OpenInstagram(url: string){
let app;
if (this.platform.is('ios')) {
app = 'instagram://';
} else if (this.platform.is('android')) {
app = 'com.instagram.android';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("instagram://"+url, '_system'), //Not working
(no: boolean) => window.open("https://"+url, '_system')
);
}
OpenTwitter(url: string){
let app;
if (this.platform.is('ios')) {
app = 'twitter://';
} else if (this.platform.is('android')) {
app = 'com.twitter.android';
}
this.appAvailability.check(app)
.then(
(yes: boolean) => window.open("twitter://"+url, '_system'), //Not working
(no: boolean) => window.open("https://"+url, '_system')
);
}
编辑
做了一些调试,所有的功能都执行了,我发现它不执行或不起作用的地方是Instagram或Twitter的应用程序是否可用。 (Facebook 运行良好)
我尝试了一些变体,代码对我来说看起来不错,有什么想法吗?
Instagram - 应在应用内打开 link:
(yes: boolean) => window.open("instagram://"+url, '_system')
Twitter 应在应用内打开 link:
(yes: boolean) => window.open("twitter://"+url, '_system')
所以我想出了问题。 Twitter 和 Instagram 必须使用一种格式。
Instagram:
window.open("instagram://user?username=whateverusername", '_system')
推特:
window.open('twitter://user?screen_name=whateverusername', '_system')