2012-03-13 39 views
1

我在執行這個代碼:在應用程序內購買 - SKProduct請求失敗,

if ([SKPaymentQueue canMakePayments]) 
{ 
    // Display a store to the user. 
    NSLog(@"Device Can Make Payments"); 
    SKProductsRequest *ProductRequst = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObjects:@"slalomtfcoins", nil]]; 
    ProductRequst.delegate = self; 
    [ProductRequst start]; 
} 
else { 
    // Warn the user that purchases are disabled. 
    NSLog(@"Device Can't Make Payments"); 
    UIAlertView *thealert = [[UIAlertView alloc]initWithTitle:@"Your Device Limited" message:@"we have noticed that you device restrictions setting are currently limited. you can change it ny going to Settings -> General -> Restrictions and turn it off" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
    [thealert show]; 
    [thealert release]; 
} 



-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ 
SKProduct *VailProduct = nil; 
NSLog(@"%d",[response.products count]); 
int count = [response.products count]; 
if (count>0) { 
    VailProduct = [response.products objectAtIndex:0]; 
    NSLog(@"Products are availble"); 
} else if (!VailProduct){ 
    NSLog(@"Products are Not availble"); 
}  

}

和日誌打印 「產品不是availble的」。 我的p.list中的包ID是正確的 ,產品ID與itunes連接相同。

是什麼問題?

感謝

+0

如果你有隻是在iTunes連接中創建產品,有時需要一段時間(幾個小時或更長時間)才能測試它們。 – 2012-03-13 18:45:02

回答

1

要嘗試的東西。

  • 刪除然後重新下載Xcode中配置的配置文件和 設備
  • 從設備上刪除應用程序
  • 註銷商店
  • 列表項
  • 硬重啓設備
  • 構建並運行應用程序
  • 再試一次

我發現的另一個修復可能不會幫助,但您可以嘗試創建一個新的測試帳戶用戶並嘗試一個。既然你的問題只是驗證,而不是購買,那可能不會有幫助。我只是提到它,以防你在路上遇到問題。

此外,如果這是第一次這樣做,你應該仔細檢查應用程序ID和產品id。

1

你運行從Xcode中的應用程序?如果您使用的是「環境的沙箱」對於在應用程序內購買使用未發佈的應用程序,你必須在Xcode中使用的「環境運行-sandbox「

1

如果您的設備不在美國商店,那麼可以通過在設備和切換商店中轉到iTunes來修復沙盒中的錯誤。當您在應用程序中再次嘗試購買時,應該會提示更換回其他商店。

還要確保您在設備上進行測試,而不是在模擬器上進行測試,並且您使用通過iTunes Connect創建的測試帳戶。

0

關於xCode 4.5.1我確定(因爲我嘗試),您可以使用iPhone模擬器來進行所有應用內購買流程。
它只是有點慢,有時會超時,所以你必須重試購買或重新開始模擬(在模擬器和iPhone中)。
在代碼中,您可以設置一個Bool,並在成功購買流程後爲其分配TRUE。使用NSLog確保一切順利。
之後,您可以使用該布爾滿足您的所有需求。

另一件事:你必須確保產品標識是完全正確的,例如:
com.example.myapp.purchase1
com.example.myapp.purchase2
...
把這些值在iTunes Connect和您的應用程序中。

也許你不得不等待只爲iTunes的更新一點時間(對我來說,我不知道爲什麼,等待的時間真的很短:只需一兩分鐘甚至更少)