I am trying to validate if facebook exists before opening it, but in IOS the code does not work, it does not validate if it exists.
openAppUrl(app: string, name: string, id?: string) {
switch (app) {
case 'facebook':
this.launchApp(
'fb://',
'com.facebook.katana',
'fb://profile/' + id,
'fb://page/' + id,
'https://www.facebook.com/' + name);
break;
case 'instagram':
this.launchApp(
'instagram://',
'com.instagram.android',
'instagram://user?username=' + name,
'instagram://user?username=' + name,
'https://www.instagram.com/' + name);
break;
case 'twitter':
this.launchApp(
'twitter://',
'com.twitter.android',
'twitter://user?screen_name=' + name,
'twitter://user?screen_name=' + name,
'https://twitter.com/' + name);
break;
case 'youtube':
this.launchApp(
'youtube://',
'com.google.android.youtube',
'https://www.youtube.com/channel/' + name,
'https://www.youtube.com/channel/' + name,
'https://www.youtube.com/channel/' + name);
break;
default:
break;
}
}
private launchApp(iosApp: string, androidApp: string, appUrlIOS: string, appUrlAndroid: string, webUrl: string) {
let app: string;
let appUrl: string;
if (this.platform.is('ios')) {
app = iosApp;
appUrl = appUrlIOS;
} else if (this.platform.is('android')) {
app = androidApp;
appUrl = appUrlAndroid;
} else {
const browser: InAppBrowserObject = this.iab.create(webUrl, '_system');
return;
}
this.appAvailability.check(app).then(
() => {
// success callback, the app exists and we can open it
const browser: InAppBrowserObject = this.iab.create(appUrl, '_system');
},
() => {
// error callback, the app does not exist, open regular web url instead
const browser: InAppBrowserObject = this.iab.create(webUrl, '_system');
}
);
}
1 post - 1 participant