开发者

how to get the all the identifier in in app purchase

开发者 https://www.devze.com 2023-03-27 02:28 出处:网络
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

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开发者_StackOverflow 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.


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"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消