当我addPayment
到空defaultQueue()
时,我可以验证现在只有一个交易存在。但是,我的paymentQueue(_:updatedTransactions:)
被多次调用,每次队列都包含原始事务的附加副本!
所以,我添加了付款(Xcode 6.4上的Swift 1.2,目标是OS 10.10):
public func purchase() {
if let product = product,
let payment = SKPayment.paymentWithProduct(product) as? SKPayment
where state == .Available {
nslog("before purchase \(SKPaymentQueue.defaultQueue().transactions)")
SKPaymentQueue.defaultQueue().addPayment(payment)
nslog("after purchase \(SKPaymentQueue.defaultQueue().transactions)")
}
}
将以下内容打印到控制台:
2015-08-04 14:12:28.887 MyApp[33753:10941171] before purchase [] --> StoreKitDelegate.swift/purchase() 65
2015-08-04 14:12:28.887 MyApp[33753:10941171] after purchase [<SKPaymentTransaction: 0x6080000032d0>] --> StoreKitDelegate.swift/purchase() 67
然后,我的paymentQueue(_:updatedTransactions:)
被调用两次,首先是包含该一个事务的队列,然后第二次包含另外一个相同的事务:
2015-08-04 14:12:28.888 MyApp[33753:10941440] StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0>
payment queue <SKPaymentQueue: 0x608000006fd0>
with transactions:
<SKPaymentTransaction: 0x6080000032d0>
--> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 274
2015-08-04 14:12:28.888 MyApp[33753:10941440] transaction state Purchasing: <SKPaymentTransaction: 0x6080000032d0>
StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0> --> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 282
2015-08-04 14:12:28.889 MyApp[33753:10941440] StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0>
payment queue <SKPaymentQueue: 0x608000006fd0>
with transactions:
<SKPaymentTransaction: 0x6080000032d0>
<SKPaymentTransaction: 0x610000000f20>
--> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 274
2015-08-04 14:12:28.889 MyApp[33753:10941440] transaction state Purchasing: <SKPaymentTransaction: 0x610000000f20>
StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0> --> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 282
当我取消交易并再次调用paymentQueue(_:updatedTransactions:)
时,队列现在包含三个交易!
2015-08-04 14:13:38.128 MyApp[33753:10943465] StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0>
payment queue <SKPaymentQueue: 0x608000006fd0>
with transactions:
<SKPaymentTransaction: 0x6080000032d0>
<SKPaymentTransaction: 0x610000000f20>
<SKPaymentTransaction: 0x608000003200>
--> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 274
2015-08-04 14:13:38.128 MyApp[33753:10943465] transaction state Failed: <SKPaymentTransaction: 0x608000003200>
StoreKitDelegate instance <MyApp.StoreKitDelegate: 0x608000006fe0> --> StoreKitDelegate.swift/paymentQueue(_:updatedTransactions:) 288
请注意,每次都引用相同的委托对象。队列也是如此。所以问题不在于我正在注册多个代表等......
我得到的唯一领先是,工具付款后检测到StoreKit
小泄漏:
Leaked Object # Address Size Responsible Library Responsible Frame
OS_dispatch_queue 1 0x7fa81205db30 128 Bytes StoreKit __47-[SKProductsRequest issueRequestForIdentifier:]_block_invoke_2
Malloc 32 Bytes 1 0x7fa8105da530 32 Bytes StoreKit __47-[SKProductsRequest issueRequestForIdentifier:]_block_invoke_2
......交易取消后再次:
Leaked Object # Address Size Responsible Library Responsible Frame
SKMutablePayment 1 0x7fa812077ad0 16 Bytes StoreKit -[SKPaymentTransaction initWithDictionary:]
SKPaymentInternal 1 0x7fa812054e90 48 Bytes StoreKit -[SKPayment init]
__NSCFString 1 0x7fa812009980 64 Bytes Foundation _getStringAtMarker
存在一个问题(Multiple SKPaymentTransaction),但是没有足够的问题可以判断问题是否相同,也没有解决问题的答案(除了通常的“你忘记完成了交易“)。
非常感谢任何帮助或见解。