Linking.canOpenURL returns true for IOS and false for Android : React Native

1.1k Views Asked by At

I have a simple string "twist" being passed on from the backend which is not a urlimage of simulator

My code for linking is as follows

console.log(url);     
let linkOpened = false;     
Linking.canOpenURL(url).then((canOpen) => {       
console.log("canOpen : ", canOpen);       
if (canOpen) {         
Linking.openURL(url);         
linkOpened = true;       
} else {         
console.log("i am calling");       
}     
});

As we can see "twist" is a string and not a URL which cannot be opened. The same code on android emulator returns false which is the correct result but true on IOS which is incorrect

IOS Watchman Output

None of the answers on github/stackoverflow/apple dev forums work for me

I have also added this in my info.plist

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>twist</string>
        <string>nothing</string>
    </array>

Running on XCODE 14 Node 165.13.0

Kindly assist me. :)

1

There are 1 best solutions below

0
On

Linking on backend using https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

It is directly linking ios nsurl TO javascript string which is causing error for now use following code and wait for there update

const url = 'twist:';
console.log(url);
let linkOpened = false;
if (url.search(':') != -1) {
  console.log('url', url.search(':'));
  try {
    linkOpened = await Linking.canOpenURL(url);
  } catch (error) {}
}

console.log('linkOpened', linkOpened);