iOS集成@ajith-ab/react-native-receive-sharing-intent报文件类型无效错误求助
解决iOS集成@ajith-ab/react-native-receive-sharing-intent时的"file type is Invalid"错误
1. 检查Info.plist的文件类型配置
确保iOS项目的Info.plist中正确声明了要接收的文件类型,添加对应UTI(Uniform Type Identifiers):
- 打开
ios/[你的项目名]/Info.plist - 添加
CFBundleDocumentTypes数组,示例配置:
<key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>Image</string> <key>LSHandlerRank</key> <string>Alternate</string> <key>LSItemContentTypes</key> <array> <string>public.image</string> <string>public.jpeg</string> <string>public.png</string> </array> </dict> <dict> <key>CFBundleTypeName</key> <string>Document</string> <key>LSHandlerRank</key> <string>Alternate</string> <key>LSItemContentTypes</key> <array> <string>public.text</string> <string>public.pdf</string> </array> </dict> </array>
同时确认开启文件共享:
<key>UIFileSharingEnabled</key> <true/>
2. 验证iOS原生代码的类型判断逻辑
检查库的iOS原生文件RNReceiveSharingIntent.m中handleShare方法的类型校验逻辑,确认是否遗漏了你要接收的文件UTI,若有自定义类型需手动添加到允许列表。
3. 清理缓存并重新构建
- 执行命令清理iOS依赖:
pod deintegrate && pod install - 删除Xcode的Derived Data:Xcode → Preferences → Locations → Derived Data,打开文件夹后删除对应项目缓存
- 重启模拟器/真机,重新运行项目
4. 确认共享文件的实际类型
测试时共享的文件需在你配置的支持类型范围内,比如若只声明了jpeg/png,共享webp格式图片就会触发错误,可通过iOS文件应用查看文件详细类型。
5. 调整库版本
若为新版本引入的问题,尝试升级到最新版或回退到之前集成成功的版本:
npm install @ajith-ab/react-native-receive-sharing-intent@[你之前成功的版本号]
之后重新执行pod install并构建项目
内容的提问来源于stack exchange,提问作者Gobinda Saha
相关产品推荐
相关产品推荐

