ios - Error when call In App Purchase - swift -


i facing problem when calling function below (or purchase product):

func restorecompletedtransactions(){ skpaymentqueue.defaultqueue().restorecompletedtransactions(); }

it return error below:

cannot connect itunes store" userinfo={nslocalizeddescription=cannot connect itunes store, sserrorhttpstatuscodekey=503}

what bugs? how can solved it?

thanks

i had issue before ! fixed. make sure log out of app store regular account , itunes.

next time test iap on device, log in sandbox account. should work.

also, if doesn't fix problem, have @ this: my iap isn't working. bugs @ func paymentqueue

it contains code iaps (which works) , tips fix issues. hope answer helpful ;)

here full iap code :

import uikit import storekit   class gameviewcontroller: uiviewcontroller, adbannerviewdelegate, skproductsrequestdelegate, skpaymenttransactionobserver, gkgamecentercontrollerdelegate,gadbannerviewdelegate{       @iboutlet var outremoveads: uibutton!     @iboutlet var outrestorepurchases: uibutton!       override func viewdidload() {         super.viewdidload()      }      override func viewwillappear(animated: bool) {         super.viewwillappear(animated)          if nsuserdefaults.standarduserdefaults().objectforkey("val") != nil {             print("has value.")             banner.removefromsuperview()             bannergoogle.removefromsuperview()             outremoveads.removefromsuperview()             outrestorepurchases.removefromsuperview()             removeinterfrom = 1         }         else {             print("no value.")         }          if(skpaymentqueue.canmakepayments()){             print("iap enabled, loading...")             let productid:nsset = nsset(objects:"iap id")             let request: skproductsrequest = skproductsrequest(productidentifiers: productid as! set<string>)             request.delegate = self             request.start()         }         else{             print("please enable iaps")          }      }       //iap ads      @ibaction func removeads(sender: uibutton) {         product in list{             let prodid = product.productidentifier             if (prodid == "iap id"){                 p = product                 buyproduct()                 break             }         }     }     @ibaction func restorepurchases(sender: uibutton) {         skpaymentqueue.defaultqueue().restorecompletedtransactions()     }       //iap functions      var list = [skproduct]()     var p = skproduct()      func removeads(){         banner.removefromsuperview()         bannergoogle.removefromsuperview()         outremoveads.removefromsuperview()         outrestorepurchases.removefromsuperview()         let thevalue = 10         nsuserdefaults.standarduserdefaults().setobject(thevalue, forkey: "val")         nsuserdefaults.standarduserdefaults().synchronize()     }      func buyproduct(){         print("buy: "+p.productidentifier)         let pay = skpayment (product: p)         skpaymentqueue.defaultqueue().addpayment(pay skpayment)     }      func productsrequest(request: skproductsrequest, didreceiveresponse response: skproductsresponse) {         print("product request")         let myproduct = response.products          product in myproduct{             print("product added")             print(product.productidentifier)             print(product.localizedtitle)             print(product.localizeddescription)             print(product.price)              list.append(product skproduct)         }     }      func paymentqueue(queue: skpaymentqueue, updatedtransactions transactions: [skpaymenttransaction]) {         print("add payment")          transaction:anyobject in transactions{             let trans = transaction as! skpaymenttransaction             print(trans.error)             switch trans.transactionstate{             case .purchased:                 print("iap unlocked")                 print(p.productidentifier)                  let prodid = p.productidentifier string                 switch prodid{                 case "iap id":                     print("remove ads")                     removeads()                 default:                     print("iap not setup")                 }                 queue.finishtransaction(trans)                 break             case .failed:                 print ("buy error")                 queue.finishtransaction(trans)                 break             default:                 print("default: error")                 break             }         }     }      func paymentqueuerestorecompletedtransactionsfinished(queue: skpaymentqueue) {         print("purchases restored")          _ = []         transaction in queue.transactions {             let t: skpaymenttransaction = transaction skpaymenttransaction              let prodid = t.payment.productidentifier string             switch prodid{             case "iap id":                 print("remove ads")                 removeads()             default:                 print("iap not setup")             }           }     }     func finishtransaction(trans:skpaymenttransaction){         print("finshed transaction")     }      func paymentqueue(queue: skpaymentqueue, removedtransactions transactions: [skpaymenttransaction]) {         print("remove transaction")     } } 

put:

skpaymentqueue.defaultqueue().addtransactionobserver(self)  

in viewdidload or viewdidappear


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -