RMStore In App Purchase Unknown Product Identifier - ios

I have spent all day trying to get an in app purchase to work in my app, and everything that I have tried to make it work results in a 'Unkown Product Identifier' response from RMStore. I have tried everything on this list: http://troybrant.net/blog/2010/01/invalid-product-ids/
My Code is:
if ([RMStore canMakePayments]) {
_products = #[#"com.afterdark.afterdark.usersaleslisting"];
[[RMStore defaultStore] requestProducts:[NSSet setWithArray:_products] success:^(NSArray *products, NSArray *invalidProductIdentifiers) {
NSLog(#"Request Success");
NSString *productID = _products[0];
SKProduct *product = [[RMStore defaultStore] productForIdentifier:productID];
NSLog(#"IAP ID: %#",productID);
NSLog(#"IAP TITLE: %#",product.localizedTitle);
NSLog(#"IAP PRICE: %#",[RMStore localizedPriceOfProduct:product]);
[[RMStore defaultStore] addPayment:productID success:^(SKPaymentTransaction *transaction) {
NSLog(#"Payment Succes");
} failure:^(SKPaymentTransaction *transaction, NSError *error) {
NSLog(#"Payment Failed: %#",error.localizedDescription);
}];
} failure:^(NSError *error) {
NSLog(#"Request Failed: %#",error.localizedDescription);
}];
}
Itunes Connect - In App Purchases:
Xcode - In App Purchases Capability
I have completely run out of ideas of how to get this to work, anyone have any ideas? Any help will be appreciated. Thank you in advance.

So, I have finally got this working. I contacted apple and it turns out the only reason it wasn't working is because something had gone wrong on their servers when I created the IAP in iTunes Connect, they promptly resolved the issue.

Related

How to get transactionID & receipt from MKStoreKit?

I've implemented MKStoreKit successfully and get notifications successfully after purchasing.
I need to get transactionID & receipt simply but I'm not sure how to get transactionID & receipt from response parameter note.
[[NSNotificationCenter defaultCenter] addObserverForName:kMKStoreKitProductPurchasedNotification
object:nil
queue:[[NSOperationQueue alloc] init]
usingBlock:^(NSNotification *note) {
NSLog(#"Purchased/Subscribed to product with id: %#", [note object]);
}];
I get my IAP productID from note parameter, when it is purchased successfully but seems like it doesn't include transactionID & receipt.
I'm pretty sure the callback block should return necessary informations including transactionID & receipt.
Do I think wrong or this library doesn't support this feature?
After struggling, I finally went to RMStore instead of MKStoreKit.
Here are some of my codes.
[[RMStore defaultStore] addPayment:"YOUR_IAP_PRODUCT_ID" success:^(SKPaymentTransaction *transaction) {
NSString* transactionID = transaction.transactionIdentifier;
NSString* receipt = #"";
NSData *data = [NSData dataWithContentsOfURL:[RMStore receiptURL]];
if(data != nil ) {
receipt = [data base64EncodedStringWithOptions: 0];
}
} failure:^(SKPaymentTransaction *transaction, NSError *error) {
NSLog(#"Something went wrong");
}];

How to test In-app purchase in Sandbox mode iOS?

Am new to In-app purchase integration in iOS application. I have done the coding in the project level and I have created a Sandbox user in iTunes Connect. I read many tutorials and Apple Document to test the In-App purchase in DEV mode.
As per the document I have removed the APPLE ID from iPad Settings and launched the app from Xcode. But, I didn't received the Account Alert from the app. Also, my products are returning empty in SKProductRequest delegate method didReceiveResponse. I have posted my code for your reference. Can you please help me on this? Am working since last two days. Please help me. Thanks in advance.
- (void) getAvailProducts
{
NSLog(#"Fetching Available Products");
NSSet *productIdentifiers = [NSSet setWithObjects:#"com.test.testios.monthly", #"com.test.testios.yearly" ,nil];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self;
[self.productsRequest start];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
//SKProduct *validProduct = nil;
DebugLog(#"\n Products: %#", response.products);
NSUInteger count = [response.products count];
NSLog(#"Request Count: %lu", (unsigned long)count);
if (count > 0)
{
self.validatedProducts = response.products;
DebugLog(#“\n Products: %#", response.products);
self.validationCheck = TRUE;
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
// Check subscription
}
else
{
// No products found….
}
}
Also, I tried with "monthly and yearly" instead of "com.test.testios.monthly and com.test.testios.yearly". But, no results.
Edit: Am getting the mentioned ProductIds are invalid in the following code,
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(#"Invalid product id: %#" , invalidProductId);
}
Thank you all.
Fixed the issue and tested the In-App purchase in Sandbox environment. Following items fixed my issue,
1. iTunes Agreement was not accepted.
2. Tax and Payment details was not added.
3. Added correct Product Identifier in project.

Issue with InApp purchase in Sandbox mode: SKProductsRequest delegate returns inconsistent response

When requesting for in-app auto renewable subscription products from apple, I sometimes get valid products but most of the times I get invalidProductIdentifiers in SKProductsResponse object. I wrote a small piece of code to verify this inconsistency in response:
-(void)viewDidAppear:(BOOL)animated{
[self getProductsFromApple];
}
-(void)getProductsFromApple{
SKProductsRequest *_productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:#"2"]];
[_productRequest setDelegate:self];
[_productRequest start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSLog(#"Invalid %#", response.invalidProductIdentifiers);
NSLog(#"Valid %#", response.products);
if (response.invalidProductIdentifiers && [response.invalidProductIdentifiers isKindOfClass:[NSArray class]] && response.invalidProductIdentifiers.count) {
[self getProductsFromApple];
}
}
This sometimes succeeds after n calls to apple server.Our team has escalated the issue to apple, we are waiting for there response.
Has anyone faced this issue, kindly suggest how you were able to test in-apps payment ?

IOS in-app purchases stopped working suddenly, fetching null identifiers

My in-app purchases were working until yesterday and today I am submitting my app for review. The only change that I made is that in the app page in the iTunes, I connected my app (by checking) with the in-app purchases.
From that time, every time I try in my debug app to buy something with my test account, I am getting this error:
NSInvalidArgumentException', reason: 'Invalid product identifier: (null)'
I have already:
re-installed my app
logged out from my store and used again my test account
but today nothing seems to work. The exact same code was working perfect yesterday, with the same test account.
May it be because I did this change in itunes? I am worrying what would happen when my app gets approved and goes online.
Any help is greatly appreciated.
EDIT:
The problem is that the array _products stays nil.
- (void)reload {
_products = nil;
NSLog(#"reload is called");
[[VimaIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(#"Success from AppStore");
}
}];
for (SKProduct* product in _products) {
NSLog(#"In-app item:%#",product.localizedTitle);
}
}
The Success log message is never called. Yesterday I had no problem, with the same code.
EDIT:
after a lot of tries, it works. Without changing anything. It seems that the server takes a lot of time to respond back. However, I cannot buy the product since I get an "cannot connect to itunes". Why that might happen?
EDIT2:
In other tries, the problem seems to be in this code:
pragma mark - SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(#"Loaded list of products...");
_productsRequest = nil;
NSArray * skProducts = response.products;
for (SKProduct * skProduct in skProducts) {
NSLog(#"Found product: %# %# %0.2f",
skProduct.productIdentifier,
skProduct.localizedTitle,
skProduct.price.floatValue);
}
_completionHandler(YES, skProducts);
_completionHandler = nil;
}
after the for loop. Especially, I get a BAD_ACCESS in line: _completionHandler(YES, skProducts);
A problem with the Xcode 5 simulator has been reported but not fixed. See this post describing the situation.
Actually the problem was that during these days the whole Apple Dev Center was down, so the above code is working for anyone else who is looking for an example.

GameCenter not updating leaderboard

Using the sandboxed Gamecenter.
No matter what I do the scores never appear in a leaderboard.
I am using the following code:
- (void)scoreReported: (NSError*) error {
NSLog(#"%#",[error localizedDescription]);
}
- (void)submitScore{
if(self.currentScore > 0)
{
NSLog(#"Score: %lli submitted to leaderboard %#", self.currentScore, self.currentLeaderBoard);
[gameCenterManager reportScore: self.currentScore forCategory: self.currentLeaderBoard];
}
}
And scoreReported doesnt produce an error, yet the score doesnt appear in the leaderboard. I know the category is correct as I use currentLeaderBoard in:
- (void)showLeaderboard {
NSLog(#"leaderboard = %#", self.currentLeaderBoard);
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.category = self.currentLeaderBoard;
//leaderboardController.category = nil;
leaderboardController.timeScope = GKLeaderboardTimeScopeWeek;
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController: leaderboardController animated: YES];
}
}
I have tried the usual
2 different sandbox GC accounts to get the leaderboard working
Even tried 4 different GC accounts each logging in on both the simulator (iOS 6.1) and device (iOS 6.0.1)
Yet still no joy
any suggestions - or is it just that the sandboxed gamecenter is far too buggy!!! (I would raise a bug about sandbox but the apple bug reporting form has a bug in it so that doesnt work either)
Score reporting to Game Center works almost immediately for me, even in sandbox mode.
Here are the few things you can try
Make sure the the Leaderboard identifiers are correct when reporting scores (Should exactly match with "Leaderboard ID"s in iTunesConnect)
Try Deleting the test data under "Manage Game Center" section of iTunesConnect
Delete the application, launch "Game Center" application in your device and goto "Games" tab and remove your app. Reinstall the app and try reporting the score again.
Make sure [gkScore reportScoreWithCompletionHandler:^(NSError *error) doesn't return any error
For those who want to know this what I changed my submitScore method to:
- (void)submitScore {
GKScore * GCscore = [[GKScore alloc] initWithCategory:self.currentLeaderBoard];
GCscore.value = [[NSUserDefaults standardUserDefaults] integerForKey:#"NEWSCORE"];
[GCscore reportScoreWithCompletionHandler:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (error == NULL) {
NSLog(#"Score Sent");
} else {
NSLog(#"Score Failed, %#",[error localizedDescription]);
}
});
}];
}
and it worked

Resources