【发布时间】:2018-05-14 09:09:54
【问题描述】:
我目前有一个 Ionic 应用程序,可以在 InAppBrowser 中打开一个网站。
每次您移动到另一个 URL 时,它都会检查域,如果它是 Facebook、Twitter 或 Instagram URL,它将 - 1. 检查手机是否安装了应用程序 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 - 应该打开应用内的链接:
(yes: boolean) => window.open("instagram://"+url, '_system')
Twitter 应该打开应用内的链接:
(yes: boolean) => window.open("twitter://"+url, '_system')
【问题讨论】:
-
您尝试过什么调试?是否甚至调用了应用程序特定的方法?
-
嗨,做了一些调试并用我的结果编辑了帖子。谢谢
标签: angularjs ionic-framework ionic3 inappbrowser