2012-03-27 6 views
1

관찰자 클래스에서 메인 클래스로 알림을 전달하는 알림 설정이있는 인앱 구매 섹션을 수행 중입니다. 나는이 부호를 가지고있다NSNotification이 왜 반복 되는가?

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { 
    for(SKPaymentTransaction *transaction in transactions) { 
     switch (transaction.transactionState) { 

      case SKPaymentTransactionStatePurchasing: 
       // Item is still in the process of being purchased 

       break; 

      case SKPaymentTransactionStatePurchased: 
       // Item was successfully purchased! 

       // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- 
       // The purchased item ID is accessible via 
       // transaction.payment.productIdentifier 


       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DataComplete object:nil] ; 
       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DataCompletehindi object:nil]; 
       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DataCompletetamil object:nil]; 
       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DataCompletetelugu object:nil]; 
       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_DataCompletekannada object:nil]; 
       // After customer has successfully received purchased content, 
       // remove the finished transaction from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 


      case SKPaymentTransactionStateRestored: 
       // Verified that user has already paid for this item. 
       // Ideal for restoring item across all devices of this customer. 

       // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- 
       // The purchased item ID is accessible via 
       // transaction.payment.productIdentifier 

       // After customer has restored purchased content on this device, 
       // remove the finished transaction from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
       break; 

      case SKPaymentTransactionStateFailed: 
       // Purchase was either cancelled by user or an error occurred. 
       [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_Datacomplteing object:nil]; 
       if (transaction.error.code != SKErrorPaymentCancelled) { 
} 
       // Finished transactions should be removed from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
       break; 
     } 
    } 
} 

나는이 주된 통역에이 통보를 건네지 만, 나는 반복적 인 통보를 받고있다. 알림은 매번 반복되며 알림 이름에 해당하는 관찰자 클래스에서 올바른 알림을받지 못했습니다. 어떻게 해결할 수 있습니까?

편집 : 나는이 같은 다섯 alertviews이 :

다음
if 
{ 
} 
elseif 
{ 
} 
else if 
{ 
} 
else if(alertView == kannadaPurchasedAlert) 
{ 
    if (buttonIndex==0) 
    {       
     NSString *connectionstring = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"]]; 

     if ([connectionstring length]==0) { 
      proAlertView *alert = [[proAlertView alloc]initWithTitle:nil message:@"you are not connected to the internet" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
      [alert setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:1.0]]; 
      [alert show]; 
      [alert release]; 
    } 
    else 
    { 
     [NSThread detachNewThreadSelector: @selector(spinBegininapp) toTarget:self withObject:nil]; 
     // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID. 
     SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"com.touch.MyApp.MyApp.Kannada"]; 

     // Assign an Observer class to the SKPaymentTransactionObserver, 
     // so that it can monitor the transaction status. 
     [[SKPaymentQueue defaultQueue] addTransactionObserver:inappObserver]; 

     // Request a purchase of the selected item. 
     [[SKPaymentQueue defaultQueue] addPayment:paymentRequest]; 
     // Register observer for when download of data is complete 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadDataCompletekannada:) name:NOTIF_DataCompletekannada object:nil]; 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadDataCompleting:) name:NOTIF_Datacomplteing object:nil]; 
     amtk = 0.0;       
    } 
} 

내가

extern NSString * const NOTIF_DataComplete; 
extern NSString * const NOTIF_Datacomplteing; 
extern NSString * const NOTIF_FIRSTLAUNCH; 
extern NSString * const NOTIF_DataCompletehindi; 
extern NSString * const NOTIF_DataCompletetamil; 
extern NSString * const NOTIF_DataCompletetelugu; 
extern NSString * const NOTIF_DataCompletekannada; 
+0

메인 클래스에서 알림을 추가 할 위치를 게시 할 수 있습니까? – danh

+0

@danh yeaa reply.i에 대한 감사합니다 .i는 inapp.so의 다른 제품 ID로 다운로드 할 5 권의 책을 가지고 있습니다. 5 가지 버튼이 있습니다. 각 버튼은 각 언어 팩에 해당하므로, 이름에 대한 알림을 전달합니다. 내 편집을 참조하십시오. – stackiphone

+0

@danh 한 가지 더, evry 것은 첫 번째 알림이있는 버튼을 누른 다음 두 번째 예를 들어이 NOTIF_DataComplete, then NOTIF_DataComplete 힌트를 사용하여 ther 버튼을 누른 다음 올바른 순서로 누른 다음 순서대로 버튼을 누르면 완벽하게 작동합니다. NOTIF_DataCompletekannada를 포함하여 알림을 탭하면 처음으로 NOTIF_DataComplete 알림을 받게됩니다. – stackiphone

답변

0

을 넣어 .H 파일 에서을 어디 NOTIF_DataCompleteXXX이 선언되고? 문자열을 지정하지 않으면 모두 동일한 "빈 이름의"알림이며 각 알림은 모든 관찰자를 트리거합니다.

+0

haii 나는 이것을 다음과 같이 메인 클래스의 구현 파일 앞에 둔다. NSString * const NOTIF_DataComplete = @ "DataComplete"; NSString * const NOTIF_Datacomplteing = @ "DataCompleting"; NSString * const NOTIF_DataCompletehindi = @ "DataCompletehindi"; NSString * const NOTIF_DataCompletetamil = @ "DataCompletetamil"; NSString * const NOTIF_DataCompletetelugu = @ "DataCompletetelugu"; NSString * const NOTIF_DataCompletekannada = @ "DataCompletekannada"; – stackiphone

+0

어떤 도움 ???? 감사 – stackiphone

0

문제는 아마도 addObversvers에 놓여 있습니다. 그것들은 누적 적입니다. 즉, 새로운 콜백이 호출 될 때마다 알림 센터에 등록됩니다. 메서드에서 한 번만 호출하면 메서드가 한 번만 호출되는지 확인하십시오. 예를 들어 viewDidAppear : 메서드는 뷰 컨트롤러의 라이프 사이클에서 여러 번 호출 될 수 있습니다. viewDidLoad에 옵저버를 설정하고 dealloc 메소드에서 옵저버를 해제하는 것이 가장 좋습니다.

관련 문제