iOS 应用内购买 - 未收到任何产品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7947805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS in app purchase - no products received
提问by Hyman BeNimble
I'm trying to add in-app purchase to my app, following the techniques described here :
我正在尝试按照此处描述的技术将应用内购买添加到我的应用中:
Introduction to In-App Purchases in iOS 6 Tutorial
I've added a product via itunes connect, which has an id set up like this:
我通过itunes connect添加了一个产品,它的id设置如下:
com.mycompany.myapp.myproduct1
The bundle id (specified in the p-list and also on the app store) is set up like this:
捆绑 ID(在 p-list 和应用商店中指定)设置如下:
com.mycompany.myapp
I'm using the helper class from the tutorial, IAHelper, to handle the purchase functionality (relevant code shown below). It also has a subclass which is essentially used to add the id of the in-app product(s) to the IAHelper's array of products ids.
我正在使用教程 IAHelper 中的帮助程序类来处理购买功能(相关代码如下所示)。它还有一个子类,主要用于将应用内产品的 id 添加到 IAHelper 的产品 id 数组中。
In order to test the code, I created a button labeled "show products" which calls this method:
为了测试代码,我创建了一个标记为“show products”的按钮,它调用了这个方法:
- (IBAction) showProducts {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productsLoaded:) name:kProductsLoadedNotification object:nil];
Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus == NotReachable) {
NSLog(@"No internet connection!");
} else {
if ([InAppMyAppAPHelper sharedHelper].products == nil) {
// here's where it calls the helper class method to request the products
[[InAppMyAppAPHelper sharedHelper] requestProducts];
self.hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
_hud.labelText = @"Loading vocabulary...";
[self performSelector:@selector(timeout:) withObject:nil afterDelay:30.0];
}
}
}
This is the method to request products from iTunesConnect, called above:
这是从上面调用的 iTunesConnect 请求产品的方法:
- (void)requestProducts {
self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers] autorelease];
_request.delegate = self;
[_request start];
}
(Note that the variables preceded by "_" refer to the actual variables of the same name sans the underscore per several synthesize statements)
(注意“_”前面的变量指的是同名的实际变量,每个合成语句都没有下划线)
Finally, this is the method (in IAHelper) that gets notified when the response is received:
最后,这是在收到响应时收到通知的方法(在 IAHelper 中):
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(@"IAHelper, received products results...");
self.products = response.products;
self.request = nil;
// Here's the loop to list the products received
for (id product in _products){
NSLog(@"IAHelper, received product is: %@", product);
}
[[NSNotificationCenter defaultCenter] postNotificationName:kProductsLoadedNotification object:_products];
}
In the above, the log statements show the method is called, but the loop to print the received products doesn't list anything.
在上面,日志语句显示方法被调用,但打印接收到的产品的循环没有列出任何内容。
So it looks as if it's not finding the product in iTunes connect. Yet, I've set up a product there, and the id of the product is the same as the bundle id, plus the product identifier, i.e.
所以看起来好像没有在 iTunes Connect 中找到该产品。然而,我已经在那里设置了一个产品,产品的 id 与捆绑包 id 相同,加上产品标识符,即
bundle id: com.mycompany.myapp
product id: com.mycompany.myapp.product1
I've checked that several times.
我已经检查过好几次了。
I noticed that iTunes lists the status of the ad-in product as "ready to submit". Is there an additional step I need to make to make it available?
我注意到 iTunes 将广告产品的状态列为“准备提交”。我是否需要执行其他步骤才能使其可用?
Overall, what am I doing wrong?
总的来说,我做错了什么?
回答by tiguero
I run into the exact similar problem. Here are some steps that needs to be adressed/checked after reading this technical notefrom Apple:
我遇到了完全类似的问题。以下是在阅读Apple 的这份技术说明后需要解决/检查的一些步骤:
- Create a unique App ID
- Enable in-app purchasing for this App ID
- Generate and install a new provisioning profile on your device
- Update the bundle ID and code signing profile in Xcode
- Check that your project's .plist Bundle ID match your App ID
- Complete your contract, tax, and banking Information. You need a VALID contract
- 创建唯一的 App ID
- 为此 App ID 启用应用内购买
- 在您的设备上生成并安装新的配置文件
- 在 Xcode 中更新包 ID 和代码签名配置文件
- 检查您项目的 .plist Bundle ID 是否与您的 App ID 匹配
- 填写您的合同、税务和银行信息。您需要一份有效的合同
As mentioned by the official doc there is NOneed to submit binaries neither submit screenshot of in-app purchase. I have seen a lot of missleading info about this on various blogs.
正如官方文档中提到有否需要提交的二进制文件既不提交应用程序内购买的屏幕截图。我在各种博客上看到了很多关于此的误导性信息。
After checking you have addressed each point in this list, delete your app and reinstall it.
在检查您已解决此列表中的每一点后,删除您的应用程序并重新安装它。
I was basically missing two things on my side: setting up correctly my contract for ios Paid app and i didn't install the new provisioning profile on my device. May be that was your issue?
我基本上错过了两件事:正确设置我的 ios 付费应用合同,并且我没有在我的设备上安装新的配置文件。可能那是你的问题?
回答by Peter B. Kramer
Getting no valid products returned in productsRequest:didReceiveResponse is a well known issue. There are many reasons, some given in TN2259 especially FAQ#6. Usually the problem is that the app is not directing itself towards the sandbox. Often that is because the developer did not do these 3 things in order: 1) delete old builds of the app (delete, not overwrite) 2) log out of the app store on the device using the settings app 3) run the app from Xcode on a device (not a simulator) and log into the store using a test user only when asked by the app store.
在 productsRequest:didReceiveResponse 中没有返回有效产品是一个众所周知的问题。原因有很多,一些在 TN2259 中给出,尤其是 FAQ#6。通常问题是应用程序没有将自己导向沙箱。通常这是因为开发人员没有按顺序执行以下 3 件事:1) 删除应用程序的旧版本(删除,而不是覆盖) 2) 使用设置应用程序从设备上注销应用程序商店 3) 运行应用程序在设备(不是模拟器)上安装 Xcode,并仅在应用商店询问时才使用测试用户登录商店。
回答by Harin
I have same problem while i m testing application on simulator.Try it in Device and its work for me.
我在模拟器上测试应用程序时遇到同样的问题。在设备中尝试它,它对我有用。
回答by Anita
I had the same issue. I filled the agreement for in app purchase, complete your contract, tax, and banking information so you have a valid contract. Also I added screenshots to the sections (App Store Promotion (Optional) and Review Information even though its says optional) in App Store Connect (in app purchases). Make sure your products in In-App Purchases have status Ready to Submit. Finally after that I got products.
我遇到过同样的问题。我填写了应用内购买协议,填写了您的合同、税务和银行信息,这样您就有了一个有效的合同。此外,我还在 App Store Connect(在应用程序购买中)的部分(App Store 促销(可选)和评论信息,即使它说是可选的)添加了屏幕截图。确保您在应用内购买中的产品处于准备提交状态。终于在那之后我得到了产品。
回答by JanB
I had a similar problem. I used code that was working in another app for IAPs so it should have been working, but I was getting an Invalid Product ID error and no results received. It turned out that it was a timing issue. I was trying to process the returned products before they'd been returned to the app, so the error was terminating the app before the products had time to be loaded! My program logic was:
我有一个类似的问题。我使用了在另一个应用程序中用于 IAP 的代码,因此它应该可以正常工作,但是我收到了无效的产品 ID 错误并且没有收到任何结果。原来是时间问题。我试图在退回的产品返回到应用程序之前对其进行处理,因此错误是在产品加载时间之前终止应用程序!我的程序逻辑是:
- User opens store view & IAP products are loaded
- A UITableView is loaded with a list of the products (but from a locally held array)
- The user clicks the buy button on a table cell - if this happens too quickly, the actual products haven't been returned yet - app crashes
- 用户打开商店视图并加载 IAP 产品
- UITableView 加载了产品列表(但来自本地保存的数组)
- 用户单击表格单元格上的购买按钮 - 如果这发生得太快,实际产品尚未返回 - 应用程序崩溃
Answer for me was to build the table from the returned products (should have been obvious to me in the first place!) so the user couldn't continue until they had been loaded correctly
我的答案是根据返回的产品构建表格(一开始对我来说应该是显而易见的!)所以用户在正确加载之前无法继续
回答by Dima Deplov
Answer for Swift projects with same error:
回答具有相同错误的 Swift 项目:
My error was here:
我的错误在这里:
//identifiers: [String]
let productIDs = Set(arrayLiteral: identifiers) as Set<NSObject>!
let request = SKProductsRequest(productIdentifiers: productIDs)
But this code will lead to an error with code = 0 message Cannot connect to iTunes Store. Let's look to the SKProductsRequest input argument type:
但此代码将导致错误代码 = 0 消息无法连接到 iTunes Store。让我们看看 SKProductsRequest 输入参数类型:
SKProductsRequest(productIdentifiers: Set<NSObject>!)
SKProductsRequest(productIdentifiers: Set<NSObject>!)
So, code above looks legit. But it doesn't! Swift Set
is the problem, considering that in input argument we see Swift Set!
所以,上面的代码看起来是合法的。但事实并非如此!SwiftSet
是问题所在,考虑到在输入参数中我们看到了 Swift Set!
Found the answer while iterating some IAP lesson. Here is the working code:
在迭代一些 IAP 课程时找到了答案。这是工作代码:
let productIDs = NSSet(array: identifiers)
let request = SKProductsRequest(productIdentifiers: productIDs as! Set<NSObject>)
You mustuse NSSet for now, although Swift Set is already available and it's set as input argument type! Looks like a bug for me, I'll fire a bug.
你现在必须使用 NSSet,尽管 Swift Set 已经可用并且它被设置为输入参数类型!对我来说看起来像是一个错误,我会触发一个错误。
回答by Ricardo Barroso
We were stuck a while with the same problem trying to run it on the simulator.
我们在模拟器上运行它时遇到了同样的问题。
After try it on a real Apple TV device (connected via USB) we started getting valid product IDs.
在真正的 Apple TV 设备(通过 USB 连接)上试用后,我们开始获得有效的产品 ID。
Then you only have to request the payment of one of these products on your code and you should be able to be requested to authenticate (with a sandbox user) and approve your purchase on the Apple TV.
然后,您只需在您的代码中请求支付这些产品之一,您应该能够被要求进行身份验证(与沙盒用户)并批准您在 Apple TV 上的购买。
回答by Basheer_CAD
If you are testing on the simulator follow the steps on this link: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/DevelopingwithStoreKit/DevelopingwithStoreKit.html#//apple_ref/doc/uid/TP40008267-CH103-SW1
如果您在模拟器上进行测试,请按照此链接上的步骤操作:https: //developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/DevelopingwithStoreKit/DevelopingwithStoreKit.html#//apple_ref/doc/uid /TP40008267-CH103-SW1
回答by Hyman BeNimble
I think I may have found the answer here.
我想我可能在这里找到了答案。
This wording from the in-app purchase web page led me to it:
应用内购买网页上的这个措辞让我想到了它:
The first In-App Purchase for an app must be submitted for review at the same time that you submit an app version. You must do this on the Version Details page. Once your binary has been uploaded and your first In-App Purchase has been submitted for review, additional In-App Purchases can be submitted using the table below.
What you can do to get around the catch-22 of not wanting to submit an app for review when you haven't tested the in-app purchase code is to submit it for review, and then immediately reject it on your own. This gives it a status of "developer rejected".
当您尚未测试应用程序内购买代码时,您可以做些什么来解决不想提交应用程序以供审核的第 22 条规则,即提交应用程序以供审核,然后立即自行拒绝。这使它处于“开发人员拒绝”状态。
Than you can add your product, According to the blog,
比你可以添加你的产品,根据博客,
After saving the product, just choose the “Submit with app binary” option. This will tie the product to the app binary, so when you finally submit the 100% complete app binary, the product will be submitted as well.