ios - In-app purchase entitlement to your app id -
i confused, dont know how can add in-app purchase existing app. when in 'capabilities' choose on in-app purchase show me error add in app purchase entitlement app id
. added app id in dev center , in-app purchase in itunesconnect. bundle id sk.freetech.zatracenacestina.intro
, in-app purchase set sk.freetech.zatracenacestina.intro.package
dont know can fill it?
thank you
you can follow these tutorial 1. http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial 2. http://www.tutorialspoint.com/ios/ios_in_app_purchase.htm 3. http://code4app.net/ios/in-app-purchase/4fc85be56803fa4a49000000
create class name iaphelper subclass nsobject
#import <storekit/storekit.h> uikit_extern nsstring *const iaphelperproductpurchasednotification; typedef void (^requestproductscompletionhandler)(bool success, nsarray * products); @protocol inapppurchasedelegate <nsobject> @optional -(void)transactionsucsess:(nsstring *)transactionid; -(void)transactiononrestore:(nsstring *)transactionid; -(void)transactiononfail; @end @interface iaphelper : nsobject @property(nonatomic,readwrite)id<inapppurchasedelegate> delegate; - (id)initwithproductidentifiers:(nsset *)productidentifiers; - (void)requestproductswithcompletionhandler:(requestproductscompletionhandler)completionhandler; - (void)buyproduct:(skproduct *)product; - (bool)productpurchased:(nsstring *)productidentifier; - (void)restorecompletedtransactions; @end
in iaphelper.m
import "iaphelper.h"
#import <storekit/storekit.h> nsstring *const iaphelperproductpurchasednotification = @"iaphelperproductpurchasednotification"; @interface iaphelper () <skproductsrequestdelegate, skpaymenttransactionobserver> @end @implementation iaphelper { skproductsrequest * _productsrequest; requestproductscompletionhandler _completionhandler; nsset * _productidentifiers; nsmutableset * _purchasedproductidentifiers; } - (id)initwithproductidentifiers:(nsset *)productidentifiers { if ((self = [super init])) { // store product identifiers _productidentifiers = productidentifiers; // check purchased products _purchasedproductidentifiers = [nsmutableset set]; (nsstring * productidentifier in _productidentifiers) { bool productpurchased = [[nsuserdefaults standarduserdefaults] boolforkey:productidentifier]; if (productpurchased) { [_purchasedproductidentifiers addobject:productidentifier]; nslog(@"previously purchased: %@", productidentifier); } else { nslog(@"not purchased: %@", productidentifier); } } // add self transaction observer [[skpaymentqueue defaultqueue] addtransactionobserver:self]; } return self; } - (void)requestproductswithcompletionhandler:(requestproductscompletionhandler)completionhandler { _completionhandler = [completionhandler copy]; _productsrequest = [[skproductsrequest alloc] initwithproductidentifiers:_productidentifiers]; _productsrequest.delegate = self; [_productsrequest start]; } - (bool)productpurchased:(nsstring *)productidentifier { return [_purchasedproductidentifiers containsobject:productidentifier]; } - (void)buyproduct:(skproduct *)product { nslog(@"buying %@...", product.productidentifier); skpayment * payment = [skpayment paymentwithproduct:product]; [[skpaymentqueue defaultqueue] addpayment:payment]; } #pragma mark - skproductsrequestdelegate - (void)productsrequest:(skproductsrequest *)request didreceiveresponse:(skproductsresponse *)response { nslog(@"loaded list of products..."); _productsrequest = nil; nsarray * skproducts = response.products; (skproduct * skproduct in skproducts) { nslog(@"found product: %@ %@ %0.2f", skproduct.productidentifier, skproduct.localizedtitle, skproduct.price.floatvalue); } _completionhandler(yes, skproducts); _completionhandler = nil; } - (void)request:(skrequest *)request didfailwitherror:(nserror *)error { nslog(@"failed load list of products."); _productsrequest = nil; _completionhandler(no, nil); _completionhandler = nil; } #pragma mark skpaymenttransactionobserver - (void)paymentqueue:(skpaymentqueue *)queue updatedtransactions:(nsarray *)transactions { (skpaymenttransaction * transaction in transactions) { switch (transaction.transactionstate) { case skpaymenttransactionstatepurchased: [self completetransaction:transaction]; break; case skpaymenttransactionstatefailed: [self failedtransaction:transaction]; break; case skpaymenttransactionstaterestored: [self restoretransaction:transaction]; default: break; } }; } - (void)completetransaction:(skpaymenttransaction *)transaction { nslog(@"completetransaction..."); [self providecontentforproductidentifier:transaction.payment.productidentifier]; [[skpaymentqueue defaultqueue] finishtransaction:transaction]; if(_delegate) [_delegate transactionsucsess:transaction.payment.productidentifier]; } - (void)restoretransaction:(skpaymenttransaction *)transaction { nslog(@"restoretransaction..."); [self providecontentforproductidentifier:transaction.originaltransaction.payment.productidentifier]; [[skpaymentqueue defaultqueue] finishtransaction:transaction]; if(_delegate) [_delegate transactiononrestore:transaction.payment.productidentifier]; } - (void)failedtransaction:(skpaymenttransaction *)transaction { nslog(@"failedtransaction..."); if (transaction.error.code != skerrorpaymentcancelled) { nslog(@"transaction error: %@", transaction.error.localizeddescription); } [[skpaymentqueue defaultqueue] finishtransaction: transaction]; if(_delegate) [_delegate transactiononfail]; } - (void)providecontentforproductidentifier:(nsstring *)productidentifier { [_purchasedproductidentifiers addobject:productidentifier]; [[nsuserdefaults standarduserdefaults] setbool:yes forkey:productidentifier]; [[nsuserdefaults standarduserdefaults] synchronize]; } - (void)restorecompletedtransactions { [[skpaymentqueue defaultqueue] restorecompletedtransactions]; } @end
create class rageiaphelper subclass of iaphelper
#import "iaphelper.h" @interface rageiaphelper : iaphelper + (rageiaphelper *)sharedinstance; @end
in rageiaphelper.m
#import "rageiaphelper.h" @implementation rageiaphelper + (rageiaphelper *)sharedinstance { static dispatch_once_t once; static rageiaphelper * sharedinstance; dispatch_once(&once, ^{ nsset * productidentifiers = [nsset setwithobjects: @"your identifier",@"your identifier", nil]; sharedinstance = [[self alloc] initwithproductidentifiers:productidentifiers]; }); return sharedinstance; } @end [[rageiaphelper sharedinstance] setdelegate:(id)self]; [[rageiaphelper sharedinstance] requestproductswithcompletionhandler:^(bool success, nsarray *products) { if (success) { totalproduct_arr =products; (skproduct *s in totalproduct_arr) { nslog(@"product identifier %@",[s productidentifier]); if ([[s productidentifier]isequaltostring:fullversion]) { [self.btnfullversion setenabled:yes]; } else if ([[s productidentifier]isequaltostring:remove_ads]) { [self.btnremovead setenabled:yes]; } } } else{ uialertview *alertfail=[[uialertview alloc] initwithtitle:@"product not found" message:@"fails load product.." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alertfail show]; } }];
and buy product
[[rageiaphelper sharedinstance] buyproduct:product];
Comments
Post a Comment