响应本机openUrl Facebook Instagram Twitter

时间:2019-07-08 19:42:02

标签: javascript reactjs react-native

当我打开Twitter或单击“后退”按钮从我的应用程序从instagram返回时,我得到了这个奇怪的错误。 Facebook代码非常有效,但我的问题是instagram和twitter。

预先感谢

enter image description here enter image description here

代码:

//render
let facebook = '123546565767';
let instagram = 'love_food';
let twitter = 'theworldoffunny';


onPress={() => Facebook(facebook)} etc....


    Instagram = (username) => {
        const instagramApp = `instagram://user?username=${username}`;
        const instagramWebsite = `http://instagram.com/_u/${username}`;
        Linking.openURL(instagramApp)
            .then((supported) => Linking.openURL(supported ? instagramApp : instagramWebsite))
            .catch((err) => console.error('An error occurred', err));
    };

    Twitter = (username) => {
        const twitterApp = `twitter://user?screen_name=${username}`;
        const twitterWebsite = `http://www.twitter.com/${username}`;

        Linking.canOpenURL(twitterApp)
            .then((supported) => Linking.openURL(supported ? twitterApp : twitterWebsite))
            .catch((err) => console.error('An error occurred', err));
    };

    Facebook = (username) => {
        const facebookApp = `fb://page/${username}`;
        const facebookWebsite = `https://fb.com/${username}`;
        Linking.canOpenURL(facebookApp)
            .then((supported) => Linking.openURL(supported ? facebookApp : facebookWebsite))
            .catch((err) => console.error('An error occurred', err));
    };

0 个答案:

没有答案