dpa99c / react-native-launch-navigator

A React Native module for launching today's most popular navigation/ride apps to navigate to a destination.
143 stars 34 forks source link

iOS getAvailableApps() wrong results #5

Closed irodeanu closed 5 years ago

irodeanu commented 5 years ago

I'm submitting a ... (check one with "x"):

Bug report

Environment information

Runtime issue

Related code:

LaunchNavigator.getAvailableApps()

Console output


{"_40":0,"_65":0,"_55":null,"_72":null}
dpa99c commented 5 years ago

getAvailableApps() is used by the example app project and appears to return the expected data structure; if I modify the console.log() statement in the example to this:

console.log("->getAvailableApps(): "+JSON.stringify(apps));

The output I get from an iPhone 7 running iOS 12.1 is this:

->getAvailableApps(): {"sygic":false,"taxis_99":false,"tomtom":false,"waze":false,"cabify":false,"gaode":false,"citymapper":false,"yandex":false,"here_maps":false,"navigon":false,"lyft":false,"transit_app":false,"maps_me":false,"apple_maps":true,"moovit":false,"uber":false,"baidu":false,"google_maps":false}

Please try building and running the example app project to confirm you get the same results.

irodeanu commented 5 years ago

On example project:

let apps = LaunchNavigator.getAvailableApps();

console.log(JSON.stringify(apps));

Response

{"_40":0,"_65":0,"_55":null,"_72":null}

dpa99c commented 5 years ago

OK, I think I see the problem here: the documentation for getAvailableApps() is wrong. It indicates that the result is returned synchronously, but because getAvailableApps() is a native module function, the result is returned asynchronously via a Promise.

So try this:

LaunchNavigator.getAvailableApps()
    .then((apps) => {
        console.log("->getAvailableApps(): "+JSON.stringify(apps));
    })
    .catch((error) => {
        console.error(error);
    });

I'll update the documentation to make this clear and check if any other functions are wrongly documented as returning results sychronously.

irodeanu commented 5 years ago

Yes, it's working. Tank you.

Anyway, as an alternative solution, I tried that:

if (await Linking.canOpenURL('waze://')) { options.push(LaunchNavigator.APP.WAZE); }

dpa99c commented 5 years ago

OK, great.

I'll reopen this issue as I still need to fix the documentation because it's currently wrong. Can be closed once docs are updated.