내가 인앱 구매를 추가 할 수 있도록 this tutorial을 따라갔습니다. 그것은 잘 작동하지만, 지금은 비 소모품 IAP를 추가하려고합니다. 내 두 번째 제품 ID를 정의하고 구매 버튼을위한 메소드를 만들었지 만,이 추가 항목에 대해 다른 SKProductsRequest를 작성해야하는지, 아니면 같은 항목을 사용하는지 등등 ...더 많은 인앱 구매
여기에 있습니다. 내 전체 코드입니다.
#define kRemoveAdsProductIdentifier @"099"
#define kDoubleEarningRateProductIdentifer @"199"
- (void)removeAds{
NSLog(@"User requests to remove ads");
if([SKPaymentQueue canMakePayments]){
NSLog(@"User can make payments");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kRemoveAdsProductIdentifier]];
productsRequest.delegate = self;
[productsRequest start];
}
else{
NSLog(@"User cannot make payments due to parental controls");
//this is called the user cannot make payments, most likely due to parental controls
}
}
- (void)doubleEarningRate{
NSLog(@"User requests 2x earning rate");
if([SKPaymentQueue canMakePayments]){
NSLog(@"User can make payments");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kDoubleEarningRateProductIdentifer]];
productsRequest.delegate = self;
[productsRequest start];
}
else{
NSLog(@"User cannot make payments due to parental controls");
//this is called the user cannot make payments, most likely due to parental controls
}
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *validProduct = nil;
int count = [response.products count];
if(count > 0){
validProduct = [response.products objectAtIndex:0];
NSLog(@"Products Available!");
[self purchase:validProduct];
}
else if(!validProduct){
NSLog(@"No products available");
//this is called if your product id is not valid, this shouldn't be called unless that happens.
}
}
- (void)purchase:(SKProduct *)product{
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void) restore{
//this is called when the user restores purchases, you should hook this up to a button
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
if(SKPaymentTransactionStateRestored){
NSLog(@"Transaction state -> Restored");
//called when the user successfully restores a purchase
[self doRemoveAds];
[self doubleEarningRate];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
//called when the user is in the process of purchasing, do not add any of your own code here.
break;
case SKPaymentTransactionStatePurchased:
//this is called when the user has successfully purchased the package (Cha-Ching!)
[self doRemoveAds]; //you can add your code for what you want to happen when the user buys the purchase here, for this tutorial we use removing ads
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction state -> Purchased");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Transaction state -> Restored");
//add the same code as you did from SKPaymentTransactionStatePurchased here
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
//called when the transaction does not finnish
if(transaction.error.code != SKErrorPaymentCancelled){
NSLog(@"Transaction state -> Cancelled");
//the user cancelled the payment ;(
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
-(void)doRemoveAds
{
areAdsRemoved = true;
NSLog(@"Ads Removed");
[topBanner removeFromSuperview];
}
-(void)doDoubleEarningRate
{
}
또한 각 부분이 무엇을 나에게 설명 사과 문서를 읽어,하지만 난 아직도 내가 다른 구매를 추가 할 수있는 방법에 대한 우둔 오전, 및 대부분의 다른 튜토리얼 다르게 또는 오래된 수행됩니다. 또한 모든 변수와 간접 지정은 다소 위협적입니다. 그래서 누군가가 나에게 다른 구매를 추가하기위한 단계 가이드로 빠른 단계를 줄 수 있기를 바랍니다.
이 접근법은 앱 구매시 단 하나만 완벽하게 작동합니다. 그러나 더 많은 것을 추가하는 방법을 알지 못합니다. 프로그램에서 인앱 구매가 선택되는 것을 프로그램에 인식시키는 방법을 모르겠습니다.
감사합니다.