没有调用帮助... didReceiveResponse

时间:2010-11-17 05:20:04

标签: iphone iphone-sdk-3.0

向大家致以粉丝!

在这里,我仍然发现实现storekit框架的问题。 当我在我的设备上运行代码时,它发送请求但是didReceiveResponse没有被调用。我在我的代码中做错了吗? 请指导我......感谢您的帮助

- (void)viewDidLoad
{
   NSLog(@"View is loaded");

   [self requestProductData];

   if ([SKPaymentQueue canMakePayments])
   {
      NSLog(@"can make payments");

   }
   else
   {
      NSLog(@"cannot make payments");
   }

   [super viewDidLoad];
}

- (void) requestProductData
{
   NSSet *productIDs = [NSSet setWithObjects:@"com.mycompany.inapppurchasetesting.productid", nil];

   SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:productIDs];

   request.delegate = self;

   NSLog(@"Requesting");

   [request start];
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *myProduct = response.products;

    NSArray *myInvalidProducts = response.invalidProductIdentifiers;

   NSLog(@"Did recieve response");

   NSLog(@"Response count is %d",response.products.count);

   NSLog(@"Invalid response count is %d",response.invalidProductIdentifiers.count);

   for (int i = 0; i<myProduct.count; i++)
   {
        NSLog(@"t:%@",[[myProduct objectAtIndex:i] localizedTitle]);
   }

    for(int i = 0; i < myInvalidProducts.count; i++)
    {
        NSLog(@"Invalid products:%@",[myInvalidProducts objectAtIndex:i]);
    }

    // populate UI
    [request autorelease];
}

1 个答案:

答案 0 :(得分:0)

您似乎在此代码中有一些内存管理错误,但我没有看到它会阻止委托被调用的问题。

如果我没记错,StoreKit可能无法完全在模拟器上运行。你在设备上试过这个吗?

此外,根据this SO question,您可以添加错误回调以帮助诊断问题,例如:

- (void) request:(SKRequest *)request didFailWithError:(NSError *)error {
    NSString *errorMessage = [error localizedDescription]; 
    [self notifyUserInterfaceOfError:errorMessage];
}