diff --git a/Classes/InAppProductsCell.h b/Classes/InAppProductsCell.h index 871c090f5..87cf2a739 100644 --- a/Classes/InAppProductsCell.h +++ b/Classes/InAppProductsCell.h @@ -7,7 +7,7 @@ // #import - +#import @interface InAppProductsCell : UITableViewCell { } @@ -22,4 +22,6 @@ + (CGFloat)getHeight:(BOOL)maximized; +- (void)fillFromProduct:(SKProduct*)prod; + @end diff --git a/Classes/InAppProductsCell.m b/Classes/InAppProductsCell.m index fe9edc42d..ada484b50 100644 --- a/Classes/InAppProductsCell.m +++ b/Classes/InAppProductsCell.m @@ -23,6 +23,17 @@ [InAppProductsCell getHeight:isMaximized]); } +- (void)fillFromProduct:(SKProduct *)prod { + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; + [formatter setLocale:prod.priceLocale]; + [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; + NSString * formattedPrice = [formatter stringFromNumber:prod.price]; + + [_ptitle setText: [prod localizedTitle]]; + [_pdescription setText: [prod localizedDescription]]; + [_pprice setText: formattedPrice]; + [_ppurchased setOn: [[[LinphoneManager instance] iapManager] isPurchased:prod]]; +} - (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"InAppProductsCell" diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index c8a5f97cf..d79287f4b 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -24,12 +24,10 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotification"; @implementation InAppProductsManager { - bool ready; } - (instancetype)init { if ((self = [super init]) != nil) { - ready = false; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [self loadProducts]; } @@ -40,8 +38,8 @@ NSString *const kLinphoneIAPurchaseNotification = @"LinphoneIAProductsNotificati if (! [SKPaymentQueue canMakePayments]) { return; } - //TODO: move this list elsewhere - NSArray * list = [[[NSArray alloc] initWithArray:@[@"test.auto_renew_7days", @"test.non_renew", @"test.one_time", @"test.auto_renew_1month_withfree"]] autorelease]; + NSArray * list = [[[[LinphoneManager instance] lpConfigStringForKey:@"inapp_products_list"] stringByReplacingOccurrencesOfString:@" " withString:@""] componentsSeparatedByString:@","]; + _productsIDPurchased = [[NSMutableArray alloc] initWithCapacity:0]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index 59f6521cf..a45fdbcd8 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -13,13 +13,13 @@ #import "DTAlertView.h" @implementation InAppProductsTableViewController { - InAppProductsManager *iapm; NSInteger currentExpanded; + InAppProductsManager *iapm; } - (void)viewWillAppear:(BOOL)animated { - iapm = [[LinphoneManager instance] iapManager]; currentExpanded = -1; + iapm = [[LinphoneManager instance] iapManager]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onIAPPurchaseNotification:) @@ -35,6 +35,7 @@ [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneIAPurchaseNotification object:nil]; + } - (void)onIAPPurchaseNotification:(NSNotification*)notif { @@ -62,14 +63,8 @@ cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId maximized:(currentExpanded == indexPath.row)] autorelease]; } SKProduct *prod = [[[[LinphoneManager instance] iapManager] productsAvailable] objectAtIndex:indexPath.row]; - [cell.ptitle setText: [prod localizedTitle]]; - [cell.pdescription setText: [prod localizedDescription]]; - [cell.pprice setText: [NSString stringWithFormat:@"%@", [prod price]]]; - [cell.ppurchased setOn: [iapm isPurchased:prod]]; + [cell fillFromProduct:prod]; cell.isMaximized = (currentExpanded == indexPath.row); - cell.productID = prod.productIdentifier; - - LOGI(@"One more: %@", cell); return cell; } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index ceb912e53..ff2f18203 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -271,8 +271,6 @@ struct codec_name_pref_table codec_pref_table[]={ LOGE(@"cannot register route change handler [%ld]",lStatus); } - _iapManager = [[InAppProductsManager alloc] init]; - NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; self.messagePlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil] autorelease]; @@ -300,6 +298,7 @@ struct codec_name_pref_table codec_pref_table[]={ [self lpConfigSetBool:FALSE forKey:@"debugenable_preference"]; #endif } + _iapManager = [[InAppProductsManager alloc] init]; [self migrateFromUserPrefs]; } diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 01c7d6cbe..4de10f81a 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -54,4 +54,5 @@ display_filter_auto_rotate=0 [app] #contact_display_username_only=1 #contact_filter_on_default_domain=1 -inapp_receipt_validation_url=https://linphone.org/inapp/veriyReceipt \ No newline at end of file +inapp_receipt_validation_url = https://linphone.org/inapp/veriyReceipt +inapp_products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree diff --git a/Resources/linphonerc-factory~ipad b/Resources/linphonerc-factory~ipad index a23c50c5b..569c25251 100644 --- a/Resources/linphonerc-factory~ipad +++ b/Resources/linphonerc-factory~ipad @@ -52,5 +52,5 @@ stun=stun.linphone.org display_filter_auto_rotate=0 [app] -inapp_receipt_validation_url=https://linphone.org/inapp/veriyReceipt - +inapp_receipt_validation_url = https://linphone.org/inapp/veriyReceipt +inapp_products_list = test.auto_renew_7days, test.non_renew, test.one_time, test.auto_renew_1month_withfree \ No newline at end of file