ios - Payment queue does not call observer object about updated transaction? -
in app when user press buy
details , sigin uialertviewcontroller
, still set there, payment queue not call observer object updated transaction.
and not print purchased state means didnt worked.
my code written :
in .h
file
#import <uikit/uikit.h> #import <storekit/storekit.h> @interface pbcashviewcontroller : uiviewcontroller<skpaymenttransactionobserver, skproductsrequestdelegate> { } @property(strong,nonatomic) skproduct *product; @property(strong,nonatomic) nsstring *productid; @property (strong, nonatomic) iboutlet uilabel *producttitle; @property (strong, nonatomic) iboutlet uitextview *productdescription; @property (strong, nonatomic) iboutlet uibutton *buybutton; - (ibaction)buy:(id)sender;`
in .m
file
-(void)getpurchaseid { if ([skpaymentqueue canmakepayments]) { skproductsrequest *request = [[skproductsrequest alloc] initwithproductidentifiers:[nsset setwithobject:self.productid]]; request.delegate = self; [request start]; } else { _productdescription.text = @"please enable in app purchases in settings"; } } -(void)productsrequest:(skproductsrequest *)request didreceiveresponse:(skproductsresponse *)response { nsarray *products = response.products; if (products.count != 0) { _product = products[0]; _buybutton.enabled = yes; _producttitle.text = _product.localizedtitle; _productdescription.text = _product.localizeddescription; } else { _productdescription.text = @"product not found"; } products = response.invalidproductidentifiers; (skproduct *product in products) { nslog(@"product not found: %@", product); } } -(void)paymentqueue:(skpaymentqueue *)queue updatedtransactions:(nsarray<skpaymenttransaction *> *)transactions { (skpaymenttransaction *transaction in transactions) { switch (transaction.transactionstate) { case skpaymenttransactionstatepurchased: [self unlockpurchase]; [[skpaymentqueue defaultqueue] finishtransaction:transaction]; _producttitle.text = @"the product has been purchased"; break; case skpaymenttransactionstatefailed: [[skpaymentqueue defaultqueue] finishtransaction:transaction]; _producttitle.text = @"the product has not been purchased"; break; case skpaymenttransactionstaterestored: [[skpaymentqueue defaultqueue] finishtransaction:transaction]; _producttitle.text = @"restored"; break; default: break; } } } -(void)unlockpurchase { nslog(@"successfuly purchased "); }
please me on anyone.
Comments
Post a Comment