Swift IOS 13, IAP - "Cannot connect to Itunes Connect"

Viewed 258

I am using IOS 13.5 and am running into some problems when implementing IAP. I used this same exact code when i built a previous app and the payment works fine when i test run the previous app on the same physical device as i do now.

I have checked internet connection which is fine, Certificates looks good, the IAP in Itunes Connect is "Ready to submit", IAP is enabled for the app, i have made several sandbox testers with same results. I clean built and restarted computer and device but It always says Code=2 "cannot connect to Itunes Connect"

I even tried to upload a build to Itunes connect to see if it would make a difference, it didn't. I am clearly missing something and would appreciate any help regarding this issue.

Calling for purchase initiation:

IAPService.shared.purchase(product: .fullAccess)

IAPService:

class IAPService: NSObject {

private override init() {}
static let shared = IAPService()

var products = [SKProduct]()
let paymentQueue = SKPaymentQueue.default()

func getProducts() {
    let products: Set = [IAPProduct.fullAccess.rawValue]
    let request = SKProductsRequest(productIdentifiers: products)
    request.delegate = self
    request.start()
    paymentQueue.add(self)
}

func purchase(product: IAPProduct){
    guard let productToPurchase = products.filter({ $0.productIdentifier == product.rawValue}).first else { return }
    let payment = SKPayment(product: productToPurchase)
    paymentQueue.add(payment)
}

func restorePurchases(){
    print("restoring purchases")
    GlobalVariables.hasFullAccess = false
    GlobalVariables.partialAccessArrayKeys.removeAll()
    paymentQueue.restoreCompletedTransactions()
    CheckPurchase.shared.checkUserPurchase()
}}

extension IAPService: SKProductsRequestDelegate {
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        self.products = response.products
        for product in response.products {
            print(product.localizedTitle)
        }
    }
}

extension IAPService: SKPaymentTransactionObserver {
    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            print(transaction.transactionState)
            print(transaction.transactionState.status(), transaction.payment.productIdentifier)
            print(transaction.debugDescription)
            if transaction.error != nil {
                print(transaction.error)
            }
            
        }
    }
}

extension SKPaymentTransactionState {
    func status() -> String {
        switch self {
        case .deferred: return "deferred"
        case .failed: return "failed"
        case .purchased: return "purchased"
        case .purchasing: return "purchasing"
        case .restored: return "restored"
        }
    }
}

IAPProduct:

enum IAPProduct : String {
    case fullAccess = "se.marcusthuvesen.Torst.FullAccess"
}

App Delegate:

class AppDelegate: UIResponder, UIApplicationDelegate, SKPaymentTransactionObserver {

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    UIApplication.shared.isIdleTimerDisabled = true
    FirebaseApp.configure()
    IAPService.shared.getProducts()
    SKPaymentQueue.default().add(self)
    //Load game texts from FireBase
    return true
}}
1 Answers

Firstly, you need to add yourself as an observer to the paymentQueue in the App Delegate didFinishLaunchingWithOptions callback.

Where are you seeing the error message? You should see the SKProductsRequestDelegate callbacks first.

Related