Я делаю в разделе покупки приложения, который имеет параметр уведомления, который передает уведомление от класса наблюдателя в основной класс. У меня есть этот код
- (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;
}
}
}
Я передаю это уведомление своему основному классу, но получаю повторные уведомления. Уведомление повторяется каждый раз, и я не получил правильное уведомление от класса наблюдателя, соответствующего названию уведомления. Как мне это решить.
EDIT:
У меня есть пять предупреждений, как это:
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;
}
}
тогда в .h файле
Я положил
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;