Grettings to you everybody!
Here me still finding problem with implementing storekit framework. When i run the code on my device, it sends the request but the didReceiveResponse is not getting called.am i doing wrong in my code? Please guide me up...Thanks for any help
- (void)viewDidLoad
{
NSLog(@"View is loaded");
[self requestProductData];
if ([SKPaymentQueue canMakePayments])开发者_如何学C
{
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];
}
You seem to have some memory management bugs in this code, but I don't see a problem with it that would prevent the delegate from being called.
If I recall correctly, StoreKit may not fully work on the simulator. Have you tried this on the device?
Also, per this SO question, you can add a callback for errors to help diagnose your issue, like so:
- (void) request:(SKRequest *)request didFailWithError:(NSError *)error {
NSString *errorMessage = [error localizedDescription];
[self notifyUserInterfaceOfError:errorMessage];
}
精彩评论