I've imported Chartboost via headers and cannot get CBAnalytics from Chartboost.framework to call next function in Swift.
我已经通过header导入了Chartboost,但是无法从chartboot .framework获得CBAnalytics来调用Swift下一个函数。
+ (void) trackInAppPurchaseEvent:(NSData *)transactionReceipt
product:(SKProduct *)product;
I followed these instructions 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
我按照下面的说明:https://answers.chartboost.com/hc/en-us/articles/205606995 https://answers.chartboost.com/hc/en-us/articles/204639335- install - event - level - trackingviasdk #ios
1 个解决方案
#1
1
I had a pre-existing Obj-C project, so I jury-rigged it to show this call in Swift.
我有一个预先存在的object - c项目,所以我临时用Swift显示这个调用。
Here's the SDK header import I needed to add to my project's Bridging-Header.h
file:
下面是我需要添加到项目的桥接头中的SDK头文件导入。h文件:
#import <Chartboost/CBAnalytics.h>
Here's my actual Swift call:
以下是我的实际的电话:
//Swift
@objc func makeChartboostPIACall(myReceipt:NSData, myProduct:SKProduct) {
CBAnalytics.trackInAppPurchaseEvent(myReceipt, product: myProduct)
}
It SHOULD be that easy, but here's a little more detail on where those values I was passing in are coming from:
这应该很简单,但这里有更多的细节关于我传递的这些价值来自哪里:
In my case, I was passing in the values from my Obj-C code:
在我的例子中,我从我的objc代码中传递了值:
//Obj-C
[mySwiftInstance makeChartboostPIACall:transaction.transactionReceipt myProduct:myProduct];
I made that call after I had just confirmed that a payment transaction had successfully completed (SKPaymentTransactionStatePurchased
). Thus, "transaction" is a SKPaymentTransaction
object, and "myProduct" is the matching SKProduct
of what had just been purchased.
我在刚刚确认一笔付款交易已经成功完成之后(skpaymenttransactionstatepurchase)打了这个电话。因此,“事务”是一个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
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
It's worth noting that transaction.transactionReceipt
is deprecated as of iOS 7, and this is the recommended method to use going forward:
值得注意的是这笔交易。在ios7中,transactionReceipt被弃用,这是推荐的使用going forward的方法:
//Obj-C
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
#1
1
I had a pre-existing Obj-C project, so I jury-rigged it to show this call in Swift.
我有一个预先存在的object - c项目,所以我临时用Swift显示这个调用。
Here's the SDK header import I needed to add to my project's Bridging-Header.h
file:
下面是我需要添加到项目的桥接头中的SDK头文件导入。h文件:
#import <Chartboost/CBAnalytics.h>
Here's my actual Swift call:
以下是我的实际的电话:
//Swift
@objc func makeChartboostPIACall(myReceipt:NSData, myProduct:SKProduct) {
CBAnalytics.trackInAppPurchaseEvent(myReceipt, product: myProduct)
}
It SHOULD be that easy, but here's a little more detail on where those values I was passing in are coming from:
这应该很简单,但这里有更多的细节关于我传递的这些价值来自哪里:
In my case, I was passing in the values from my Obj-C code:
在我的例子中,我从我的objc代码中传递了值:
//Obj-C
[mySwiftInstance makeChartboostPIACall:transaction.transactionReceipt myProduct:myProduct];
I made that call after I had just confirmed that a payment transaction had successfully completed (SKPaymentTransactionStatePurchased
). Thus, "transaction" is a SKPaymentTransaction
object, and "myProduct" is the matching SKProduct
of what had just been purchased.
我在刚刚确认一笔付款交易已经成功完成之后(skpaymenttransactionstatepurchase)打了这个电话。因此,“事务”是一个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
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
It's worth noting that transaction.transactionReceipt
is deprecated as of iOS 7, and this is the recommended method to use going forward:
值得注意的是这笔交易。在ios7中,transactionReceipt被弃用,这是推荐的使用going forward的方法:
//Obj-C
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];