0

I have a react native project where i am sending a http request through fetch() to a page that redirects me to a url scheme like appname://data=123456.

I need to extract those data from the location url and then continue with other requests to a api. The problem is that ios has problems with this. Android chomps it righ up and it works without problems, but on ios i get a "Network request failed" result.

After some longer debugging i found out that the implementation behind react native catches a error stating "unsupported URL".

Is there any way to make this work? I was trying something along the lines of starting up an app with custom URL scheme, and now appname:// written into safari starts up my app, but it had no effect for the request.

Code i am using for the request: OAUTH2_IS_URL is https://login.server.com and action /api/login

 const postData = {username, password};
    return fetch(BuildConfig.OAUTH2_IS_URL + action, {
        method: 'POST',
        credentials: 'same-origin',
        mode: 'same-origin',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: Object.keys(postData).map(key => key + "=" + 
     encodeURIComponent(postData[key])).join('&')
    });
Anderiel
  • 173
  • 2
  • 13

1 Answers1

1

What I understood from your question is that you are trying to open up an app with the URL that comes from a fetch request.

If that is the case you should use Linking API of react-native. You can test if the URL is supported with canOpenURL() and then start the app with openURL()

Linking.canOpenURL(url).then(supported => {
  if (!supported) {
    console.log('Can\'t handle url: ' + url);
  } else {
    return Linking.openURL(url);
  }
}).catch(err => console.error('An error occurred', err));
bennygenel
  • 23,896
  • 6
  • 65
  • 78
  • The problem is the url never arrives from the request, i debugged what the url is on android. On ios i never recieve it, instead i get an error. – Anderiel Sep 25 '17 at 07:59