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

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

ios - StoreKitTest : Request product error Domain=ASDErrorDomain Code=950 "Unhandled exception"

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)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...