-2
我試圖讓這整個應用內購買工作,但我遇到了一些問題。所以我可以用我的測試用戶帳戶「購買」這些功能,但我想一次又一次地進行測試。所以我做了一個刪除方法,擺脫生成的鑰匙串並退出應用程序,然後再次構建它,並返回到「免費」狀態,在那裏我再次嘗試購買該應用程序,但這次它提供了我「你已經購買這個項目,點擊確定再次下載」,所以我點擊確定,但這次沒有任何反應,沒有功能獲得解鎖,跆拳道?應用內購買
代碼:
-(void)deleteKeyChain:(id)sender {
NSError *error = nil;
NSLog(@"delete!!!!");
[SFHFKeychainUtils deleteItemForUsername:@"someUser" andServiceName:kStoredData error:&error];
}
-(void)doFeature:(id)sender {
[newPlayer pause];
if ([self IAPItemPurchased]) {
// do the feature 2!
// featureLabel.text = @"Feature: 2";
} else {
// not purchased so show a view to prompt for purchase
askToPurchase = [[UIAlertView alloc]
initWithTitle:@"All Features"
message:@"Tap refresh anytime to read latest 5 emails. To read all emails with no ads and to continue reading in the background, please purchase the full version of this app."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK",@"Later on", nil];
askToPurchase.delegate = self;
[askToPurchase show];
[askToPurchase release];
}
}
#pragma mark StoreKit Delegate
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
// show wait view here
// statusLabel.text = @"Processing...";
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view and unlock feature 2
// statusLabel.text = @"Done!";
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Complete"
message:@"You now have the full version of Emails Aloud!!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
NSError *error = nil;
[SFHFKeychainUtils storeUsername:@"someUser" andPassword:@"pass" forServiceName:kStoredData updateExisting:YES error:&error];
// apply purchase action - hide lock overlay and
// [feature2Btn setBackgroundImage:nil forState:UIControlStateNormal];
// do other thing to enable the features
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
// statusLabel.text = @"";
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"Error payment cancelled=%d",transaction.error.code);
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
// statusLabel.text = @"Purchase Error!";
break;
default:
break;
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
// remove wait view here
// statusLabel.text = @"";
SKProduct *validProduct = nil;
int count = [response.products count];
if (count>0) {
validProduct = [response.products objectAtIndex:0];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.myapp.shit"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Not Available"
message:@"No products to purchase"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
}
}
-(void)requestDidFinish:(SKRequest *)request
{
[request release];
}
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView==askToPurchase) {
if (buttonIndex==0) {
// user tapped YES, but we need to check if IAP is enabled or not.
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.myapp.shit"]];
request.delegate = self;
[request start];
} else {
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Prohibited"
message:@"Parental Control is enabled, cannot make a purchase!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
[tmp release];
}
}
}
}
注:SomeUser的名/密碼是不是任何人的用戶名/密碼。這只是我選擇將應用程序購買中的用戶註冊到他們的設備中的文本。
是的,我有,它實際上每次我做一個新的測試用戶,但沒有到達的地步,我可以刪除鑰匙串,重新啓動應用程序,然後再次購買 – user1593518 2012-08-14 14:59:25
爲什麼你讓他們每次重新購買打開/重新啓動應用程序? – 2012-08-14 15:02:24
以及我關閉應用程序之前,我點擊一個按鈕,目標是「deleteKeyChain」方法,我想我不必重新啓動應用程序,我已經做到了,我不在,但同樣的行爲 – user1593518 2012-08-14 15:04:57