2013-01-19 201 views
1

基本上我试图让应用内购买工作,但没有运气。这里是我的代码用于请求产品的购买iOS应用内购买不起作用

- (void)requestProductData 
{ 
    NSSet *productIdentifiers=[NSSetsetWithObject:productid]; 
    request5= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject: productIdentifiers]]; 
    request5.delegate = self; 
    [request5 start]; 
} 

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response 
{ 
    myProducts = response.products; 
    for (NSString *invalidProductId in response.invalidProductIdentifiers) 
    { 
     NSLog(@"Invalid product id: %@" , invalidProductId); 
    } 
    SKProduct *selectedProduct = [myProducts objectAtIndex:0]; 
    SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct]; 
    [[SKPaymentQueue defaultQueue] addPayment:payment]; 
} 

奇怪的是,无论response.products和response.invalidProductId在them.I've 0对象已经尝试等确认供应配置文件中,APPID的事情,包ID等。此外,自从我在iTunes连接中添加应用程序内购买以来,已经过去了将近24小时。谁能帮我?

+0

您是否在iTunes Connect上设置了测试帐户?您是否使用此测试帐户登录商店,而不是真实的iTunes帐户? – rmaddy

+0

我确实创建了一个测试帐户,然后我退出了我的iTunes帐户,但正如此链接所述,您无需登录测试帐户http://developer.apple.com/library/mac/#documentation/ NetworkingInternet/Conceptual/StoreKitGuide/DevelopingwithStoreKit/DevelopingwithStoreKit.html – vicciu

+0

好点。只有在进行实际购买时才需要测试帐户,而不仅仅是列出产品。抱歉。 – rmaddy

回答

0

检查提出请求的代码。您有:

NSSet *productIdentifiers = [NSSet setWithObject:productid]; 
request5 = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: productIdentifiers]]; 

它应该是:

NSSet *productIdentifiers = [NSSet setWithObject:productid]; 
request5 = [[SKProductsRequest alloc] initWithProductIdentifiers: productIdentifiers]; 

您正在创建一组与一个对象 - 另一组的产品ID。

+0

非常感谢你rmaddy。我只是不能相信我失去了一天,这个错误:) – vicciu