내 앱에서 iap을 사용하려고합니다. 이것들은 게임 골드로 구입해야하며 한 번 이상 사용할 수 있습니다. 나는 멍청이 튜토리얼의 코드를 코드화하고 거기에서 작동한다. 누군가 내가 잘못하고있는 것을 말해 줄 수 있는가?SKProductRequest가 결과를 반환하지 않습니다.
#import "IAP.h"
#import "Money.h"
@interface IAP()
@end
@implementation IAP;
#define kStoredData @"com.AlexApps.TinyTrucks"
+(void)myIAPWithItem:(NSString *)Item{
if ([SKPaymentQueue canMakePayments]) {
NSString *PurchaseAddress = [[NSString alloc] initWithString:[NSString stringWithFormat:@"TTE_%@kGold" , Item]];
//PurchaseAddress is the appId for this in app purchase
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PurchaseAddress]];
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];
}
}
#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
break;
}
case SKPaymentTransactionStatePurchased:{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view and unlock feature 2
UIAlertView *tmp = [[UIAlertView alloc]
initWithTitle:@"Complete"
message:@"You have unlocked Feature 2!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[tmp show];
// apply purchase action - hide lock overlay and
NSLog(@"befvsda");
// do other thing to enable the features
break;
}
case SKPaymentTransactionStateRestored:{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
break;
}
case SKPaymentTransactionStateFailed:{
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"Error payment cancelled");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
// remove wait view here
break;
}
default:{
break;
}
}
}
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
// remove wait view here
SKProduct *validProduct = nil;
int count = [response.products count];
if (count>0) {
validProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.emirbytes.IAPNoob.01"];
[[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];
}
}
-(void)requestDidFinish:(SKRequest *)request
{
}
-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
#pragma mark AlertView Delegate
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
이 프로그램은이 라인에 가져옵니다
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PurchaseAddress]];
request.delegate = self;
[request start];
그럼 그냥 중지하고 다시 사과 아무것도하지 않습니다.
1. 여기에 코드를 붙여 넣으십시오. 사람들이 자르고 붙여서 코드를 보지 마십시오. 2. 애플 가이드를 사용하십시오. http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html 3. 코드에 몇 가지 중단 점을 넣고 실패 지점 또는 중단 지점까지 좁히십시오. – tassinari