2010-11-17 27 views
1

給大家嘔吐!幫助... didReceiveResponse不叫

在這裏,我仍然發現實施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]; 
} 

回答

0

你似乎在這個代碼中的一些內存管理錯誤,但我不認爲它有問題,將防止委託被調用。

如果我沒有記錯,StoreKit可能無法在模擬器上正常工作。你在設備上試過這個嗎?

而且,每this SO question,你可以添加一個回調的錯誤,以幫助診斷您的問題,像這樣:

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