fehler beim simulierten in app kauf

SpecialFighter

Aktives Mitglied
Thread Starter
Dabei seit
25.04.2012
Beiträge
1.139
Punkte Reaktionen
20
nabend zusammen,

ich habe diese code für in app purchase mit swift 2 ios9.
mein in itunes connect eingetragenes iap (in app pruchase) wird gefunden und in einer tabelle angezeigt.
diese eintrag kann man auswählen, es kommt eine alert message, wo man auf buy oder cancel drücken kann.
wenn man buy drückt kommt ein neues alert vom appstore, um den kauf zu bestätigen.


ich logge mich mit meinem sandbox user ein. nach meiner Bestätigung erhalte ich in der Konsole:
Transaction Failed


Jemand ne Idee warum?
Hier der Code:
Code:
    importUIKit
    importStoreKit
    import iAd
    protocol IAPurchaceViewControllerDelegate{
    func didBuyPremium(Index:Int)
    }
    class iAP:UIViewController,UITableViewDelegate,UITableViewDataSource,SKProductsRequestDelegate,SKPaymentTransactionObserver{
    @IBOutlet weak varLoadingScreen:UIView!
    @IBOutlet weak var tblProducts:UITableView!
    vardelegate:IAPurchaceViewControllerDelegate!
    var productIDs:Array<String!>=[]
    var productsArray:Array<SKProduct!>=[]
    var selectedProductIndex:Int!
    var transactionInProgress =false
    override func viewWillAppear(animated:Bool){
    view.bringSubviewToFront(LoadingScreen)
    LoadingScreen.hidden =false
    navigationController?.setNavigationBarHidden(false, animated:true)
    }
    override func viewDidLoad(){
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    tblProducts.delegate=self
    tblProducts.dataSource =self
    // Replace the product IDs with your own values if needed.
    productIDs.append("xxx_Iap")
    requestProductInfo()
    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
    }
    // MARK: UITableView method implementation
    func numberOfSectionsInTableView(tableView:UITableView)->Int{
    return1
    }
    func tableView(tableView:UITableView, numberOfRowsInSection section:Int)->Int{
    return productsArray.count
    }
    func tableView(tableView:UITableView, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat{
    return65
    }
    func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath)->UITableViewCell{
    let cell = tableView.dequeueReusableCellWithIdentifier("IAPCell")as!ModifyCellsIAP
    let product = productsArray[indexPath.row]
    cell.PremiumName.text = product.localizedTitle
    cell.PremiumBeschreibung.text = product.localizedDescription
    let price ="\(product.price)"
    letFormatPrice= price.stringByReplacingOccurrencesOfString(".", withString:",")
    cell.PremiumPreis.setTitle("\(FormatPrice)€", forState:.Normal)
    LoadingScreen.hidden =true
    return cell
    }
    func tableView(tableView:UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath){
    selectedProductIndex = indexPath.row
    showActions()
    tableView.cellForRowAtIndexPath(indexPath)?.selected =false
    }
    func requestProductInfo(){
    ifSKPaymentQueue.canMakePayments(){
    let productIdentifiers =NSSet(array: productIDs)
    let productRequest:SKProductsRequest=SKProductsRequest(productIdentifiers: productIdentifiers as!Set<String>)
    productRequest.delegate=self
    productRequest.start()
    }
    else{
    print("Cannot perform In App Purchases.")
    }
    }
    func showActions(){
    if transactionInProgress {
    return
    }
    let actionSheetController =UIAlertController(title:"Upgrade", message:"Möchten Sie diese Erweiterung freischalten?", preferredStyle:UIAlertControllerStyle.ActionSheet)
    let buyAction =UIAlertAction(title:"Freischalten", style:UIAlertActionStyle.Default){(action)->Voidin
    let payment =SKPayment(product:self.productsArray[self.selectedProductIndex]asSKProduct)
    SKPaymentQueue.defaultQueue().addPayment(payment)
    self.transactionInProgress =true
    }
    let cancelAction =UIAlertAction(title:"Abbrechen", style:UIAlertActionStyle.Cancel){(action)->Voidin
    }
    actionSheetController.addAction(buyAction)
    actionSheetController.addAction(cancelAction)
    presentViewController(actionSheetController, animated:true, completion:nil)
    }
    func productsRequest(request:SKProductsRequest, didReceiveResponse response:SKProductsResponse){
    if response.products.count !=0{
    for product in response.products {
    productsArray.append(product )
    }
    tblProducts.reloadData()
    }
    else{
    print("There are no products.")
    }
    if response.invalidProductIdentifiers.count !=0{
    print("Invalid: \(response.invalidProductIdentifiers.description)")
    }
    }
    func paymentQueue(queue:SKPaymentQueue, updatedTransactions transactions:[SKPaymentTransaction]){
    for transaction in transactions {
    switch transaction.transactionState {
    caseSKPaymentTransactionState.Purchased:
    print("Transaction completed successfully.")
    SKPaymentQueue.defaultQueue().finishTransaction(transaction)
    transactionInProgress =false
    delegate.didBuyPremium(selectedProductIndex)
    caseSKPaymentTransactionState.Failed:
    print("Transaction Failed");
    SKPaymentQueue.defaultQueue().finishTransaction(transaction)
    transactionInProgress =false
    default:
    print("Default: \(transaction.transactionState.rawValue)")
    }
    }
    }
    }
 
Oben Unten