response.products count始终在应用程序购买中返回0 Xcode 4 ios
我的问题很简单,当尝试在模拟器中进行应用内购买时,响应。products count始终返回0,因此不购买。。。我一直试图调试它,但没有成功。。。。代码如下:response.products count始终在应用程序购买中返回0 Xcode 4 ios,ios,xcode,in-app-purchase,storekit,Ios,Xcode,In App Purchase,Storekit,我的问题很简单,当尝试在模拟器中进行应用内购买时,响应。products count始终返回0,因此不购买。。。我一直试图调试它,但没有成功。。。。代码如下: - (IBAction)buy500Coins:(id)sender { [buyingAI startAnimating]; if (internetActive == NO) { [buyingAI stopAnimating]; askToPurchase = [[UIAlertView alloc]
- (IBAction)buy500Coins:(id)sender {
[buyingAI startAnimating];
if (internetActive == NO) {
[buyingAI stopAnimating];
askToPurchase = [[UIAlertView alloc]
initWithTitle:@"No internet connection"
message:@"It seems you are not connected to the internet. in-app purchases require a internet connection. Please connect to the internet and try again."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[askToPurchase show];
} else {
askToPurchase = [[UIAlertView alloc]
initWithTitle:@"Are you Sure?"
message:@"Are you sure you want to buy 4000 coins for 0.99$?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
askToPurchase.delegate = self;
[askToPurchase show];
[buyingAI stopAnimating];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView == askToPurchase) {
if (buttonIndex == 1) {
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.ge0rges.Meme_jump.500C"]];
request.delegate = self;
[request start];
[buyingAI startAnimating];
buyingAI.hidden = NO;
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Prohibited"
message:@"Sorry , Parental Control is enabled, you cannot make a purchase."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[tmp show];
}
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
[buyingAI stopAnimating];
SKProduct *validProduct = nil;
int count = [response.products count];
NSLog(@"%i", count);
if (count>0) {
validProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment]; // <-- KA CHING!
} else {
UIAlertView *notAvail = [[UIAlertView alloc]
initWithTitle:@"Not Available"
message:@"Sorry there seems to be a problem. Please try again later."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[notAvail show];
}
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
{
[buyingAI startAnimating];
buyingAI.hidden = NO;
break;
}
case SKPaymentTransactionStatePurchased:
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
UIAlertView *complete = [[UIAlertView alloc]
initWithTitle:@"Complete"
message:@"You have received 4000 Coins."
delegate:nil
cancelButtonTitle:@"Awesome!"
otherButtonTitles:nil, nil];
[complete show];
allCoins += 4000;
break;
}
case SKPaymentTransactionStateRestored:
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
break;
}
case SKPaymentTransactionStateFailed:
{
if (transaction.error.code != SKErrorPaymentCancelled) {
UIAlertView *failed = [[UIAlertView alloc]
initWithTitle:@"Failed"
message:@"Oops there seems to be a problem. Please try again later and make sure your internet connection is active."
delegate:nil
cancelButtonTitle:@"Ok :("
otherButtonTitles:nil, nil];
[failed show];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[buyingAI stopAnimating];
break;
}
}
}
}
-(iAction)购买500枚硬币:(id)发送者{
[buyingAI startAnimating];
如果(internetActive==否){
[buyingAI停止动画制作];
ASKTopurCase=[[UIAlertView alloc]
initWithTitle:@“没有internet连接”
消息:@“您似乎未连接到internet。应用内购买需要internet连接。请连接到internet,然后重试。”
代表:无
取消按钮:@“确定”
其他按钮类型:无,无];
[Asktopurcase show];
}否则{
ASKTopurCase=[[UIAlertView alloc]
initWithTitle:@“你确定吗?”
信息:@“您确定要以0.99美元的价格购买4000枚硬币吗?”
代表:赛尔夫
取消按钮:@“否”
其他按钮提示:@“是”,无];
asktopurcase.delegate=self;
[Asktopurcase show];
[buyingAI停止动画制作];
}
}
-(无效)alertView:(UIAlertView*)alertView单击按钮索引:(NSInteger)按钮索引{
if(alertView==asktopurcase){
如果(按钮索引==1){
如果([SKPaymentQueue canMakePayments]){
SKProductsRequest*请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@“com.ge0rges.Meme_jump.500C]”;
request.delegate=self;
[请求启动];
[buyingAI startAnimating];
buyingAI.hidden=否;
}否则{
UIAlertView*tmp=[[UIAlertView alloc]
initWithTitle:@“禁止”
消息:@“对不起,家长控制已启用,您无法购买。”
代表:无
取消按钮:@“确定”
其他按钮类型:无,无];
[tmp秀];
}
}
}
}
-(无效)产品请求:(SKProductsRequest*)请求DID接收方响应:(SKProductsResponse*)响应
{
[buyingAI停止动画制作];
SKProduct*validProduct=nil;
int count=[response.products count];
NSLog(@“%i”,计数);
如果(计数>0){
validProduct=[response.products对象索引:0];
SKPayment*payment=[SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]添加付款:付款];//必须确保标识符是正确的,但拼写错误。无效产品标识符的内容是什么?iTunesConnect中的产品状态如何?iTunesConnect表示已准备好提交应用内购买。如何从SKProductsResponse中获取无效产品标识符的内容de>我在执行以下操作时得到了com.ge0rges.Meme_jump.500C:NSLog(@“%@”,response.invalidProductIdentifiers);啊,我知道问题出在哪里了,我用了一个“j”代替了j谢谢你的启发!