how to assign skpayment applicationusername

前提是你 提交于 2021-02-05 05:27:27

问题


can we assign skpayment applicationusername?

When in app purchase is completed, I got a null applicationUsername in theSKPayment.

How do I assign a value to SKPayment applicationUsername?


回答1:


You can't assign a value to the property of an SKPayment; When you create the SKMutablePayment instance in order to submit the purchase request, your app can provide an opaque value that represents the application user id. This enables the iTunes store to detect irregular activity.

Despite its name, the applicationUsername property is not meant to hold the actual username.

A suggested approach is shown in the In-App Purchasing Programming Guide

Note that the value you assigned may not be present in the SKPayment you receive on the transaction queue.

Important

The applicationUsername property is not guaranteed to persist between when you add the payment transaction to the queue and when the queue updates the transaction. Do not attempt to use this property for purposes other than providing fraud detection.




回答2:


You can assign it like :

   // MARK: purchase SKProduct from store
    @objc func buy(product: SKProduct, withHandler handler: @escaping ((_ success : Bool , _ error :RiscoIAPManagerError? ) -> Void)) {
        let payment = SKMutablePayment(product: product)
        
        payment.applicationUsername = "applicationUsername"
        SKPaymentQueue.default().add(payment)
        // Keep the completion handler.
        productBuyComplition = handler
    }

And can get it again in

     func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
                    print(transaction.payment.applicationUsername as Any)

}



回答3:


You may not assign a read only property. The objects iOS is providing on completed transaction are immutable. To be honest Apple's API fails to properly inform the client apps about the processed transaction.



来源:https://stackoverflow.com/questions/37202248/how-to-assign-skpayment-applicationusername

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!