I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...
React Native TTS iOS 问题全解析:修复 BOOL 错误与事件监听失效(2026 实战指南)
- Get link
- X
- Other Apps
By
Errong Leng
-
React Native TTS iOS 问题全解析:修复 BOOL 错误与事件监听失效(2026 实战指南)
在 React Native 中使用文本转语音(TTS)本来很简单,但在 iOS 上却可能踩坑。
本文总结了两个非常常见但又很隐蔽的问题,并提供经过验证的解决方案。
🧨 问题一:Objective-C type BOOL is unsupported
错误信息
TextToSpeech.setDefaultRate(): Error while converting JavaScript argument to Objective C type BOOL
convert javascript argument to object C type Bool object C type bool is unsupported
🔍 根本原因
这不是你的代码问题。
这是由于 iOS 原生桥接层(Objective-C)类型定义错误导致的,尤其在 React Native 新架构(Fabric / TurboModules)下更容易触发。
部分版本的 react-native-tts 错误地使用了:
(BOOL *)onWordBoundary ❌ 错误
而 React Native bridge 不支持 BOOL 指针类型,只支持:
- BOOL
- NSNumber *
✅ 解决方案
使用已修复的 fork 版本:
@iternio/react-native-tts
npm install @iternio/react-native-tts
该版本已修复 iOS 类型问题,可以正常运行。
⚠️ 问题二:事件监听器未注册
警告信息
Sending `tts-start` with no listeners registered.
即使你已经写了监听:
Tts.addEventListener('tts-start', () => {
setIsSpeaking(true);
});
🔍 根本原因
问题在于:TTS 模块尚未初始化完成,你就注册了监听器。
- Native 层事件已触发 ✅
- JS 监听器尚未就绪 ❌
✅ 关键修复(必须做)
在使用 TTS 前,必须等待初始化:
useEffect(() => {
const init = async () => {
await Tts.getInitStatus(); // 👈 非常关键
Tts.setDefaultRate(0.5);
Tts.setDefaultPitch(1.0);
const sub = Tts.addEventListener('tts-start', () => {
setIsSpeaking(true);
});
return () => sub.remove();
};
init();
}, []);
💡 总结
- react-native-tts 在 iOS 上存在已知问题
- BOOL 错误属于 Native 层 bug,不是 JS 写法问题
- 必须调用
Tts.getInitStatus()再使用
🚀 推荐实践
- ✅ 使用
@iternio/react-native-tts - ✅ 所有调用前等待初始化
- ⚠️ 新架构(Fabric)下需特别注意兼容性
🧩 进阶建议
如果你在开发生产级应用,建议直接封装 iOS 原生 TTS:
- 使用 AVSpeechSynthesizer
- 自定义 React Native bridge
这样可以彻底避免第三方库带来的不稳定问题。
✍️ 结语
这些问题非常隐蔽,但其实很常见。如果你也遇到类似问题,希望这篇文章能帮你节省大量排查时间。
Happy coding 🚀
❤️ Support This Blog
If this post helped you, you can support my writing with a small donation. Thank you for reading.
- Get link
- X
- Other Apps
Popular Posts
A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android
By
Errong Leng
-
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...
2023, New Start! New AdSense Account! New Earnings!
By
Errong Leng
-
It's been a while after I created adsense account to display ads on this blog. A few years later the payment finally reached my payout threshold, I just found the existed adsense account is bind to China. but I moved to Canada 3 years ago. I tried to change the country of it, but just found Unfortunately it's not possible to change the country of your payment address in AdSense. If you've moved to a new country or territory, you'll need to cancel your existing AdSense account and create a new AdSense account . So I created a new adsense account today on 2023-01-12. Though new account is still under reviewing, I believe it will be approved soon. To reach out payout threshold in this year, I set up the below plan: write one blog per week day!!! write one blog per week day!!! write one blog per week day!!! Try ingress more traffic to this blog
react-native run-android : do not build/update modified code(App.js)
By
三好Daddy
-
Solution react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res c:\Users\lenger\Desktop\webrowser>react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (43ms) Scanning folders for symlinks in c:\Users\lenger\Desktop\webrowser\node_modules (38ms) Loading dependency graph, done. bundle: start bundle: finish bundle: Writing bundle output to: android/app/src/main/assets/index.android.bundle bundle: Done writing bundle output Run react-native run-android again, you will find your modification work.
Comments
Post a Comment