Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the all the identifier in in app purchase

I am creating a sample app for in app purchase. I have implemented for one product I used the following code in which I can implement the for one product purchasing, but if suppose there are more than one product then how can I get the list of all the identifiers for all the products available. Hope I am clear with the question.

I have used the following code for for one product as below.

- (void)viewDidLoad {
[super viewDidLoad];


if ([SKPaymentQueue canMakePayments]) {
        NSLog(@"Parental-controls are disabled");

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.companion.onemonth"]];
        productsRequest.delegate = self;
        [productsRequest start];
    } else {
        NSLog(@"Parental-controls are enabled");
        //com.companion.onemonth ;
    }
}


    - (IBAction)purchase {
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.companion.onemonth"];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

Through this code I can get for one product but dont know how to get multiple identifiers at run time.

like image 391
mrugen munshi Avatar asked Aug 11 '11 11:08

mrugen munshi


People also ask

What is App Store identifier?

Android. We use the Application ID (package name) to identify your app inside our system. You can find this in the app's Play Store URL after 'id'. For example, in https://play.google.com/store/apps/details?id=com.company.appname the identifier would be com. company.

What is product ID in-app purchase?

A: A product identifier is a string used to uniquely identify every product you wish to sell from your application. The App Store uses it to retrieve information about a product. It is a string identifier that can only contain alphanumeric (A-Z, a-z, 0-9), underscore (_), and period (.) characters.


2 Answers

Apple does not provide a method to get all the inapp products available for an app. They have mentioned this in their documentation. Either we should hard code this in our app or use a separate API call to return the list of products.

If we have the list of identifier with us we can get the details of all the products in one API call.

Reference: http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW11

See the diagrammatic reference, which shows a link to "Developer server"

like image 59
Nandakumar R Avatar answered Sep 27 '22 17:09

Nandakumar R


Put all your defined products hardcoded into the NSSet of SKProductsRequest:

[NSSet setWithObjecta:@"com.companion.onemonth", @"com.companion.twomonth"], nil)

and you you get an NSArray of available products in the delegate method:

(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response;

SKProductsResponse will have an array of your products.

like image 31
AlexVogel Avatar answered Sep 27 '22 16:09

AlexVogel