Recently I am facing a weird problem on IOS with React Native when using XMLHttpRequest to convert path uri to Blob. It gives a random network request error. So sometimes it works and sometimes not on the same network. The error only happens on physical IOS devices (Android works fine) and not on the IOS emulator on my computer.
I am using React Native: 0.61.5 and iOS 13. The code worked on IOS 12 devices.
Code:
export function urlToBlob(url) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.onerror = function() { reject(new Error('uriToBlob failed')); }; xhr.onreadystatechange = () => { if (xhr.readyState === 4) { resolve(xhr.response); } }; xhr.open('GET', url); xhr.responseType = 'blob'; // convert type xhr.send(); });}
I also tried react native fetch which gives the same problems.
Info.pl list
<key>NSAllowsArbitraryLoads</key><true/><key>NSExceptionDomains</key><dict><key>localhost</key><dict><key>NSExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict></dict>
I don't know if it is possible, but a solution might be to work around fetch and convert the path uri to blob without a http request.