2013-05-23 5 views
1

내 앱에서 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]; 

그럼 그냥 중지하고 다시 사과 아무것도하지 않습니다.

+0

1. 여기에 코드를 붙여 넣으십시오. 사람들이 자르고 붙여서 코드를 보지 마십시오. 2. 애플 가이드를 사용하십시오. http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html 3. 코드에 몇 가지 중단 점을 넣고 실패 지점 또는 중단 지점까지 좁히십시오. – tassinari

답변

0

위임을 설정했는지 확인하고 request.delegate = self;을 가지고 있지만 클래스 메서드에서 self을 사용하고 있습니다. 그게 어떻게 작동하는지 모르겠다.

+(void)myIAPWithItem:(NSString *)Item을 인스턴스 메서드 -(void)myIAPWithItem:(NSString *)Item으로 변경하고 Money 클래스를 인스턴스화하고 메서드를 호출합니다. 도움이되는지 확인하십시오.

+0

알았어, 내가 바꿨어. kStoredData는 바꿨지만 운이 아니었다. 이전과 같은. –

0

iTunesConnect에 제품 ID com.emirbytes.IAPNoob.01에 대한 설정을 만들었습니까?

당신이 생성하는 경우, 당신은 iTunesConnect

UPDATE 1에서 만든 하나입니다 귀하의 제품 ID com.emirbytes.IAPNoob.01의 맞춤법을 검사 : 없음 Bundle ID는 차이가 없습니다, Product ID이 다릅니다.

Bundle ID은 App에 사용되는 고유 식별자입니다. Product ID은 제품 목록을 구입할 때 사용한 고유 식별자입니다.

하자가 com.emirbytes.IAPNoob이 bundleID라고하고

  1. com.emirbytes.IAPNoob.swords - 상품 ID가 칼을
  2. com.emirbytes.IAPNoob.soldiers를 구입하는 것입니다 - 제품 ID가 Product ID를 만들려면 군인에게

를 구입하는 것입니다, 당신은 가기로했습니다 iTunesConnect으로 설정하고 하나의 앱을 만들고 제품 ID를 Manage In-App Purchases에 설정해야합니다.

+0

kStoredData가 com.emirbytes.IAPNoob.01이 아닙니다. 내 앱의 번들 ID입니다. 이게해야 할 일 이니? kStoreData가 변경되면 동일한 문제가 발생합니다. kstoredata 코드로 업데이트되었습니다. –

+0

내 업데이트 확인 @AlexPelletier – arthankamal

+0

kStoreData를 my in app 구매 제품 ID로 변경했지만 운이 아직 없습니다. 공유 할 수있는 샘플 프로젝트가 있습니까? –

관련 문제