内购 - 斯威夫特 3.0

Posted

技术标签:

【中文标题】内购 - 斯威夫特 3.0【英文标题】:IAP - Swift 3.0 【发布时间】:2017-02-16 11:15:23 【问题描述】:

我想为我的 Swift 应用程序进行 IAP,每当我尝试通过代码连接 intunes 时,我的 xcode 中缺少权利,请参阅附件。

这是我连接 iTunes 的代码。

func loadStoreProducts()


    if (SKPaymentQueue.canMakePayments())
        KVNProgress.show(withStatus: "Loading payment options")
        let productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: Set([productID]));
        productsRequest.delegate = self;
        productsRequest.start();
    else
        AppDelegate.getAppDelegate().showMessage("Your Apple account doesn't allow payments, you cannot have a JustAskMe subscription.")
    


func restoreTransactions()
    SKPaymentQueue.default().restoreCompletedTransactions()


func buyMembership(product:SKProduct)
    let payment = SKPayment(product: product)
    SKPaymentQueue.default().add(payment);


func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) 

    DispatchQueue.main.async()
        KVNProgress.dismiss()
    


    if (!response.products.isEmpty) 

        let  validProduct: SKProduct = response.products[0] as SKProduct

        if (validProduct.productIdentifier == self.productID) 
            print(validProduct.localizedTitle)
            print(validProduct.localizedDescription)
            print(validProduct.price)
            buyMembership(product: validProduct);
         else 
            // got a product that wasn't the one we asked for?
            print("Invalid product found: \(validProduct.productIdentifier)")
        
     else 
        AppDelegate.getAppDelegate().showMessage("Problems processing your payment, please try again.")
    


func request(_ request: SKRequest, didFailWithError error: Error) 

    DispatchQueue.main.async()
        KVNProgress.dismiss()
    
    // notify the user
    AppDelegate.getAppDelegate().showMessage("Problems processing your payment, please try again.")
    //log the issue.
    print(error.localizedDescription)




func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) 
    DispatchQueue.main.async()
        KVNProgress.dismiss()
    

    for transaction:AnyObject in queue.transactions
    
        let trans : SKPaymentTransaction = transaction as! SKPaymentTransaction
        let identifier : NSString = trans.payment.productIdentifier as NSString
        print(identifier)
    



func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) 
    DispatchQueue.main.async()
        KVNProgress.dismiss()
    



func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) 
    DispatchQueue.main.async()
        KVNProgress.dismiss()
    
    // notify the user
    AppDelegate.getAppDelegate().showMessage("Problems loading your previous purchases, please try again.")
    //log the issue.
    print(error.localizedDescription)

enter image description here

【问题讨论】:

【参考方案1】:

您是否在 Xcode 的 Capabilities Pane 中打开了应用内购买?

【讨论】:

【参考方案2】:

登录开发者中心,然后导航到证书、标识符和配置文件、应用 ID 并检查应用内购买是否已启用,然后重试。

【讨论】:

以上是关于内购 - 斯威夫特 3.0的主要内容,如果未能解决你的问题,请参考以下文章

玩IOS游戏怎么内购

iOS苹果内购(详细步骤)

Flutter iOS内购(代码篇-全网最全)

苹果内购是啥意思?

怎么跨区内购苹果

iOS内购丢单的解决方案