react-native-text-detector 在 android 中运行良好,但为什么它在 iOS 中总是返回 false?
react-native-text-detector worked fine in android but why it always returned false in iOS?
首先,我使用https://github.com/jeanpan/react-native-camera-roll-picker#readme从照片库中获取图像,它返回一个uri:ph://11A68DD6-A651-462D-BDAB-68FB853ED141/L0/001
然后,我使用 https://github.com/zsajjad/react-native-text-detector 从该图像中获取文本
它在 android 中运行良好,但在 iOS 中始终返回 false,我在控制台日志中发现以下错误
NSURLConnection 已完成,但出现错误 - 代码 -1002
有关详细信息,图像控件可以正确显示该图像
这是我的源代码:https://github.com/haison8x/react-native-test-ocr
该 URI 或应用程序权限有问题吗?
由于 Apple 的沙箱政策 https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html,您的应用无法直接读取相册中的照片,它会遇到错误:NSURLConnection finished with error - code -1002。
这是我的方法:
- 使用RNFS.copyAssetsFileIOS将照片复制到您的应用文档中的临时文件
- 使用 react-native-text-detector 分析临时文件
首先,我使用https://github.com/jeanpan/react-native-camera-roll-picker#readme从照片库中获取图像,它返回一个uri:ph://11A68DD6-A651-462D-BDAB-68FB853ED141/L0/001
然后,我使用 https://github.com/zsajjad/react-native-text-detector 从该图像中获取文本
它在 android 中运行良好,但在 iOS 中始终返回 false,我在控制台日志中发现以下错误
NSURLConnection 已完成,但出现错误 - 代码 -1002
有关详细信息,图像控件可以正确显示该图像
这是我的源代码:https://github.com/haison8x/react-native-test-ocr
该 URI 或应用程序权限有问题吗?
由于 Apple 的沙箱政策 https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html,您的应用无法直接读取相册中的照片,它会遇到错误:NSURLConnection finished with error - code -1002。
这是我的方法:
- 使用RNFS.copyAssetsFileIOS将照片复制到您的应用文档中的临时文件
- 使用 react-native-text-detector 分析临时文件