이 전체 인앱 구매를 시도 중이지만 몇 가지 문제가 있습니다. 따라서 테스트 사용자 계정으로 기능을 "구입"할 수는 있지만 여러 번 테스트하고 싶습니다. 그래서 생성 된 키 체인을 없애고 앱을 종료하고 다시 빌드하는 삭제 메소드를 만들었습니다. 다시 앱을 구매하려고하는 "자유"상태로 돌아 왔지만 이번에는 제공합니다. 나 "이미이 항목을 구입했으면 확인을 탭하여 다시 다운로드하십시오"라고 말합니다. 그렇기 때문에 이번에는 아무 일도 일어나지 않으며 어떤 기능도 잠금 해제되지 않습니다.인앱 구매
코드 :
-(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
왜 매번 다시 구매 하는지요? 앱을 켜거나 다시 시작 하시겠습니까? –
잘 "앱을 끄기 전에"deleteKeyChain "메소드를 타겟으로하는 버튼을 탭하면, 앱을 다시 시작해야 할 필요가 없다는 것을 알았습니다. 내가 해내지 않았지만 똑같은 동작을했습니다. – user1593518