我已通过 header 导入 Chartboost,但无法从 Chartboost.framework 获取 CBAnalytics 以调用 Swift 中的下一个函数。
+ (void) trackInAppPurchaseEvent:(NSData *)transactionReceipt
product:(SKProduct *)product;
我遵循了这些说明 https://answers.chartboost.com/hc/en-us/articles/205606995 https://answers.chartboost.com/hc/en-us/articles/204639335-Post-Install-Analytics-Event-Level-Tracking-via-SDK#ios
最佳答案
我有一个预先存在的 Obj-C 项目,所以我临时操纵它以在 Swift 中显示此调用。
这是我需要添加到项目的 Bridging-Header.h
文件中的 SDK header 导入:
#import <Chartboost/CBAnalytics.h>
这是我实际的 Swift 调用:
//Swift
@objc func makeChartboostPIACall(myReceipt:NSData, myProduct:SKProduct) {
CBAnalytics.trackInAppPurchaseEvent(myReceipt, product: myProduct)
}
应该这么简单,但这里有一些关于我传递的这些值来自何处的更多详细信息:
在我的例子中,我传递了来 self 的 Obj-C 代码的值:
//Obj-C
[mySwiftInstance makeChartboostPIACall:transaction.transactionReceipt myProduct:myProduct];
我在刚刚确认付款交易已成功完成 (SKPaymentTransactionStatePurchased
) 后调用了该电话。因此,“transaction”是一个 SKPaymentTransaction
对象,“myProduct”是刚购买的匹配 SKProduct
。
https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKPaymentTransaction_Class/index.html#//apple_ref/occ/instp/SKPaymentTransaction/transactionReceipt https://developer.apple.com/library/ios/documentation/StoreKit/Reference/SKProduct_Reference/index.html
值得注意的是 transaction.transactionReceipt
从 iOS 7 开始被弃用,这是推荐使用的方法:
//Obj-C
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
关于objective-c - 如何通过 swift 使用 Chartboost 分析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38964982/