how to assign skpayment applicationusername

后端 未结 3 493
一生所求
一生所求 2021-01-28 22:46

can we assign skpayment applicationusername?

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

How do I assign a

相关标签:
3条回答
  • 2021-01-28 23:03

    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.

    0 讨论(0)
  • 2021-01-28 23:14

    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.

    0 讨论(0)
  • 2021-01-28 23:14

    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)
    
    }
    
    0 讨论(0)
提交回复
热议问题