简体   繁体   中英

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

I have a simple string "twist" being passed on from the backend which is not a url image 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. :)

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM