1. Pour: storekit.framework Library
2. Code
1 #import<UIKit/UIKit.h>2 3 //Import Library4 #import<StoreKit/StoreKit.h>5 @interfaceViewcontroller:uiviewcontroller<skproductsrequestdelegate,skpaymenttransactionobserver>6@property (Strong, nonatomic) iboutlet Uitextfield *ProductID;7@property (Strong, nonatomic) iboutlet UIButton *Purchase;8 //xib buy button9-(Ibaction) Purchasefunc: (ID) sender;Ten @end
#import "ViewController.h"/** In the test purchase you enter the purchase user must be the user intelligence under the sandbox technical tester inside the account*/@interfaceViewcontroller () @property (Nonatomic,copy,ReadOnly) NSString *Localizedprice;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; [[Skpaymentqueue Defaultqueue] addtransactionobserver:self]; Self.productID.text=@"Com.fadada.grB";//ID of your in-product purchase }//Click-(Ibaction) Purchasefunc: (ID) Sender {NSString*product =Self.productID.text; if([Skpaymentqueue canmakepayments]) {[Self requestproductdata:product]; }Else{NSLog (@"do not allow in-app billing"); }}//Request a product- (void) Requestproductdata: (NSString *) type{NSLog (@"-------------request the corresponding product information----------------"); Nsarray*product =[[Nsarray alloc] initwithobjects:type, nil]; Nsset*nsset =[Nsset setwitharray:product]; Skproductsrequest*request =[[Skproductsrequest alloc] initwithproductidentifiers:nsset]; Request.Delegate=Self ; [Request start]; }//Receive product return information- (void) Productsrequest: (skproductsrequest *) Request Didreceiveresponse: (Skproductsresponse *) response{NSLog (@"--------------receive a product feedback message---------------------"); Nsarray*product =response.products; if([Product count] = =0) {NSLog (@"--------------No goods------------------"); return; } NSLog (@"productid:%@", response.invalidproductidentifiers); NSLog (@"number of products paid:%ld", [Product Count]); Skproduct*p =Nil; for(Skproduct *proinchproduct) {NSLog (@"%@", [pro description]); NSLog (@"%@", [pro localizedtitle]); NSLog (@"%@", [pro localizeddescription]); NSLog (@"%@", [pro price]); NSLog (@"%@", [pro productidentifier]); if([Pro.productidentifier IsEqualToString:self.productID.text]) {p=Pro; }} skpayment*payment =[Skpayment paymentwithproduct:p]; NSLog (@"Send Purchase Request"); [[Skpaymentqueue Defaultqueue] addpayment:payment];}//request failed- (voidRequest: (Skrequest *) Request Didfailwitherror: (Nserror *) error{NSLog (@"------------------Error-----------------:%@", error);}- (void) Requestdidfinish: (Skrequest *) request{NSLog (@"------------End of feedback information-----------------");}//Monitor Purchase Results- (void) Paymentqueue: (Skpaymentqueue *) queue updatedtransactions: (Nsarray *) transaction{ for(Skpaymenttransaction *traninchtransaction) { Switch(tran.transactionstate) { CaseSkpaymenttransactionstatepurchased:nslog (@"Transaction Completion"); Break; CaseSkpaymenttransactionstatepurchasing:nslog (@"Add items to the list"); Break; CaseSkpaymenttransactionstaterestored:nslog (@"have purchased a product"); Break; CaseSkpaymenttransactionstatefailed:nslog (@"Transaction Failure"); Break; default: Break; } }}//End of transaction- (void) Completetransaction: (Skpaymenttransaction *) transaction{NSLog (@"End of transaction"); [[Skpaymentqueue Defaultqueue] finishtransaction:transaction];}- (void) dealloc{[[Skpaymentqueue Defaultqueue] removetransactionobserver:self];}
3.xib
Apple Internal Purchase Demo