ios - Flutter iOS RevenueCat 未捕获异常'NSInternalInconsistencyException'
问题描述
我在控制台中收到此错误:
[Purchases] - INFO: There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.
*** Assertion failure in +[RCCommonFunctionality getPurchaserInfoWithCompletionBlock:], RCCommonFunctionality.m:118
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You must call setup first.'
*** First throw call stack:
(0x1a0379654 0x1a009bbcc 0x1a027c6ec 0x1a06c216c 0x1032908ac 0x1032cdf9c 0x1032cc0d4 0x105c3ae30 0x1053ef758 0x1056d58b4 0x1053f90ec 0x1053fb818 0x1a02f8134 0x1a02f7e50 0x1a02f752c 0x1a02f253c 0x1a02f1ba8 0x1aa461344 0x1a442d3e4 0x102c4069c 0x1a01798f0)
libc++abi.dylib: terminating with uncaught exception of type NSException
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001a016ed88 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
-> 0x1a016ed88 <+8>: b.lo 0x1a016eda4 ; <+36>
0x1a016ed8c <+12>: stp x29, x30, [sp, #-0x10]!
0x1a016ed90 <+16>: mov x29, sp
0x1a016ed94 <+20>: bl 0x1a014dad0 ; cerror_nocancel
Target 0: (Runner) stopped.
Lost connection to device.
然而,这是一个间歇性问题(即:并不总是发生)。事实上,我已经Purchases
在启动时设置了实例(即:在用户通过身份验证并获得 UID 后立即):
await Purchases.setDebugLogsEnabled(isDebugEnabled);
await Purchases.setup(kRevenueCatApiKey, appUserId: uid);
有什么我错过的吗?(但大多数时候它都有效)
解决方案
我发现了问题。所以每当getPurchaserInfo
被调用,但如果Purchaser.setup
还没有完成处理,那么它会触发这个异常。感谢上面@Cesar 的评论。
就我而言,我发现问题是因为:
- 我有两个分别处理 IAP 和业务逻辑的 Bloc。
Purchases.setup
一旦用户通过身份验证,IAP 就会调用。然后在主屏幕上,业务逻辑将通过执行检查本地数据的有效性与服务器getPurchaserInfo
。- 当互联网连接不佳并且在完成处理
getPurchaserInfo
之前被业务逻辑块触发时,就会出现问题。Purchases.setup
所以我所做的解决方案是确保业务逻辑块在 IAP 块完成后开始初始化Purchases.setup
。例如将它们放在等待每个进程的异步函数中。
推荐阅读
- java - 引起:java.lang.ClassNotFoundException:找不到类“com.google.android.gms.common.internal.zzbq”
- javascript - 迭代,检查一些表单值是否每 2 秒更新一次
- web-services - OAuth2 vs SAML vs Openid
- c# - .Net 核心单元测试
- image - 多重过滤规则不适用?
- sql - 在列中找到最大值,但仅当其他两列匹配时
- swift - 元素作为AnyObject vs element vs AnyObject?
- javascript - 根据父对象是否已经在数组中过滤对象数组
- python - 制作一个 python Tkinter 登录屏幕,用于验证来自 csv 文件的帐户详细信息
- php - 将我的 xampp 安装从 5.3 更新到 5.5 或 5.6 - on power pc mac 10.5