【发布时间】:2011-10-30 21:04:42
【问题描述】:
我正在尝试按照此处描述的技术将应用内购买添加到我的应用中:
Introduction to In-App Purchases in iOS 6 Tutorial
我通过 itunes connect 添加了一个产品,它的 id 设置如下:
com.mycompany.myapp.myproduct1
bundle id(在 p-list 和应用商店中指定)设置如下:
com.mycompany.myapp
我正在使用教程中的帮助程序类 IAHelper 来处理购买功能(相关代码如下所示)。它还有一个子类,主要用于将应用内产品的 id 添加到 IAHelper 的产品 id 数组中。
为了测试代码,我创建了一个标有“显示产品”的按钮,它调用了这个方法:
- (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];
}
}
}
这是从 iTunesConnect 请求产品的方法,上面调用:
- (void)requestProducts {
self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers] autorelease];
_request.delegate = self;
[_request start];
}
(注意,“_”前面的变量指的是同名的实际变量,没有下划线,每个综合语句)
最后,这是在收到响应时得到通知的方法(在 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];
}
在上面,日志语句显示方法被调用,但打印接收到的产品的循环没有列出任何内容。
所以它看起来好像没有在 iTunes 连接中找到产品。然而,我已经在那里设置了一个产品,产品的 id 与 bundle id 相同,加上产品标识符,即
bundle id: com.mycompany.myapp
product id: com.mycompany.myapp.product1
我已经检查了好几次了。
我注意到 iTunes 将插件产品的状态列为“准备提交”。我需要采取额外的步骤才能使其可用吗?
总的来说,我做错了什么?
【问题讨论】:
-
我有同样的问题,在我的情况下,catch 和 then 部分都在执行,不知道为什么。我在模拟器中测试。在真实设备中进行测试按预期工作
标签: ios in-app-purchase