Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to unit test my framework calling StoreKit with the new (iOS 14) StoreKitTest and I'm getting this error when I fetch products :

Error Domain=SKErrorDomain Code=0 "UNKNOWN_ERROR" UserInfo={NSLocalizedDescription=UNKNOWN_ERROR, NSUnderlyingError=0x7fab74623870 {Error Domain=ASDErrorDomain Code=950 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}}

This is my code :

import XCTest
import StoreKitTest

class FrutaTests: XCTestCase {

    var session: SKTestSession!
    var request: SKProductsRequest!
    var expectation: XCTestExpectation?

    override func setUpWithError() throws {
        session = try SKTestSession(configurationFileNamed: "Configuration")
    }

    override func tearDownWithError() throws {
        session = nil
    }

    func testFetchProducts() throws {
        let productIdentifiers = Set<String>()

        expectation = XCTestExpectation(description: "fetchProducts")

        request = SKProductsRequest(productIdentifiers: productIdentifiers)

        request.delegate = self

        request.start()

        wait(for: [expectation!], timeout: 10.0)
    }
}

extension FrutaTests: SKProductsRequestDelegate {
    func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
        print(response.products.map({$0.productIdentifier}))

        expectation?.fulfill()
    }

    func requestDidFinish(_ request: SKRequest) {
        print("DidFinishh")
    }

    func request(_ request: SKRequest, didFailWithError error: Error) {
        print(error)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

I found where the error came from : In my test target, in General, I'd removed Host Application because I didn't want the app to compile and unchecked the Allow testing Host Application APIs.

It seems that StoreKitTest requires this setting but the error is really unclear!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...