如何获得用户权利以在整个对话中持续存在 [英] How do I get user entitlements to persist across conversations
问题描述
我试图通过检查conv.user.entitlements来查看用户是否购买了产品,但购买后立即除外,这是空的。
I am trying to see if a user has purchased a product by checking conv.user.entitlements but except for immediately after purchase, this is empty.
此值以前在会话之间似乎一直存在,现在始终为空。购买后,我可以立即使用conv.user.entitlements看到该权利,但是随后它就消失了。
This value seemed to be persisting between conversations previously, now it is always empty. I am able to see the entitlement using conv.user.entitlements immediately after purchase, but then it is gone.
if (arg.purchaseStatus === 'PURCHASE_STATUS_OK') {
console.log('purchase2 ', conv.user.entitlements);
//this works as expected showing the entitlement
在日志中,我看到:Purchase2 [ {权利:[[Object]],
packageName:'com.chad.myfirstapp'}]
In the logs I see: purchase2 [ { entitlements: [ [Object] ], packageName: 'com.chad.myfirstapp' } ]
但是当我尝试在下一个中记录相同的内容时对话,我得到:
But when I try to log the same in the next conversation, I get:
purchase2 []
purchase2 [ ]
推荐答案
如果只想查看用户是否曾经购买过商品,请使用conv.user.storage来存储一个布尔值,以确定用户是否曾经购买过商品:
If you just want to see if a user has purchased an item in the past, use the conv.user.storage to store either a boolean whether the user has purchased something in the past:
conv.user.storage.hasPurchasedItem = true
或者您可以在conv中进行一系列购买.user.storage并检查其长度:
Or perhaps you can make an array of purchases in conv.user.storage and check its length:
conv.user.storage.purchases = conv.user.storage.purchases || []
conv.user.storage.purchases.push({item:bananas,cost:0.99})
这篇关于如何获得用户权利以在整个对话中持续存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!