From 76d99fa43b568c30c1d992bf8a24f36bdd837a5b Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 31 Aug 2016 10:45:55 +0200 Subject: [PATCH] inapp: terminate shop --- Classes/AssistantLinkView.m | 5 ++- Classes/AssistantView.m | 6 ++- Classes/Base.lproj/ShopView.xib | 57 ++++++++++++------------ Classes/Base.lproj/SideMenuView.xib | 46 ++++++++++--------- Classes/InAppProductsManager.m | 22 ++++----- Classes/ShopTableView.m | 25 +++++++++-- Classes/ShopView.h | 11 ++--- Classes/ShopView.m | 30 ++----------- Classes/SideMenuTableView.m | 6 +-- Resources/assistant_linphone_create.rc | 2 +- Resources/assistant_linphone_existing.rc | 2 +- Resources/linphonerc-factory | 2 +- submodules/linphone | 2 +- 13 files changed, 107 insertions(+), 109 deletions(-) diff --git a/Classes/AssistantLinkView.m b/Classes/AssistantLinkView.m index e588829a6..33806569b 100644 --- a/Classes/AssistantLinkView.m +++ b/Classes/AssistantLinkView.m @@ -55,7 +55,10 @@ linphone_account_creator_set_username( account_creator, linphone_address_get_username(linphone_proxy_config_get_identity_address(cfg))); const LinphoneAuthInfo *info = linphone_proxy_config_find_auth_info(cfg); - linphone_account_creator_set_password(account_creator, linphone_auth_info_get_passwd(info)); + if (linphone_auth_info_get_passwd(info)) + linphone_account_creator_set_password(account_creator, linphone_auth_info_get_passwd(info)); + else + linphone_account_creator_set_ha1(account_creator, linphone_auth_info_get_ha1(info)); linphone_account_creator_set_domain(account_creator, linphone_proxy_config_get_domain(cfg)); } else { LOGW(@"Default proxy is NOT a sip.linphone.org, aborting"); diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index ec85127bd..6b8131710 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -946,7 +946,8 @@ void assistant_is_account_activated(LinphoneAccountCreator *creator, LinphoneAcc ONCLICKBUTTON(sender, 100, { _waitView.hidden = NO; linphone_account_creator_set_activation_code(account_creator, ((UITextField*)[self findView:ViewElement_SMSCode inView:_contentView ofType:UITextField.class]).text.UTF8String); - if (linphone_account_creator_get_password(account_creator) == NULL) { + if (linphone_account_creator_get_password(account_creator) == NULL && + linphone_account_creator_get_ha1(account_creator) == NULL) { linphone_account_creator_activate_account(account_creator); } else { linphone_account_creator_activate_phone_number_link(account_creator); @@ -973,7 +974,8 @@ void assistant_is_account_activated(LinphoneAccountCreator *creator, LinphoneAcc _waitView.hidden = NO; if ((linphone_account_creator_get_phone_number(account_creator) != NULL) && - linphone_account_creator_get_password(account_creator) == NULL) { + linphone_account_creator_get_password(account_creator) == NULL && + linphone_account_creator_get_ha1(account_creator) == NULL) { linphone_account_creator_recover_phone_account(account_creator); } else { // check if account is already linked with a phone number. diff --git a/Classes/Base.lproj/ShopView.xib b/Classes/Base.lproj/ShopView.xib index a8b271af3..9eb9e0c22 100644 --- a/Classes/Base.lproj/ShopView.xib +++ b/Classes/Base.lproj/ShopView.xib @@ -1,41 +1,41 @@ - + - - + + - - + + - + - + - - + + - + - - - - + + + + - - + + - + - - + + - + + - + - - + + @@ -84,6 +85,6 @@ - + diff --git a/Classes/Base.lproj/SideMenuView.xib b/Classes/Base.lproj/SideMenuView.xib index 6530159ed..9c72801b9 100644 --- a/Classes/Base.lproj/SideMenuView.xib +++ b/Classes/Base.lproj/SideMenuView.xib @@ -1,8 +1,9 @@ - + - + + @@ -29,45 +30,45 @@ - + - + - + - + - + @@ -80,29 +81,27 @@ - + - + - + - - + - @@ -125,8 +124,13 @@ - + - + + + + + + diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 0cb1cca82..0acf97374 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -58,7 +58,7 @@ checkPeriod = [LinphoneManager.instance lpConfigIntForKey:@"expiry_check_period" inSection:@"in_app_purchase"]; warnBeforeExpiryPeriod = [LinphoneManager.instance lpConfigIntForKey:@"warn_before_expiry_period" inSection:@"in_app_purchase"]; lastCheck = 0; - + int testExpiry = [LinphoneManager.instance lpConfigIntForKey:@"expiry_time_test" inSection:@"in_app_purchase"]; if (testExpiry > 0){ expiryTime = time(NULL) + testExpiry; @@ -284,7 +284,7 @@ // if ([transaction.transactionIdentifier // isEqualToString:transaction.originalTransaction.transactionIdentifier]) { if (self.accountCreationData.count == 3) { - [request setMethod:@"create_account_from_in_app_purchase" + [request setMethod:@"update_expiration_date" withParameters:[NSArray arrayWithObjects:@"", [_accountCreationData objectForKey:@"phoneNumber"], receiptBase64, @"", @"apple", [_accountCreationData objectForKey:@"email"], nil]]; @@ -292,7 +292,7 @@ // otherwise simply renewing } else { if ([[self getPhoneNumber] length] > 0) { - [request setMethod:@"get_expiration_date" + [request setMethod:@"update_expiration_date" withParameters:[NSArray arrayWithObjects:[self getPhoneNumber], receiptBase64, @"", @"apple", nil]]; } else { @@ -404,7 +404,7 @@ // validation succeeded if (![response isFault] && [response object] != nil) { - if (([[request method] isEqualToString:@"get_expiration_date"]) || + if (([[request method] isEqualToString:@"get_account_expiration"]) || ([[request method] isEqualToString:@"create_account_from_in_app_purchase"])) { [_productsIDPurchased removeObject:productID]; // response object can either be expiration date (long long number or an error string) @@ -501,30 +501,30 @@ if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground){ UILocalNotification *notification = [[UILocalNotification alloc] init]; if (notification) { - + notification.category = notificationCategory; notification.repeatInterval = 0; notification.applicationIconBadgeNumber = 1; notification.alertBody = expireText; - + [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; } - + }else{ UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Account expiring" message:expireText preferredStyle:UIAlertControllerStyleAlert]; - + UIAlertAction* buyAction = [UIAlertAction actionWithTitle:@"Buy" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [PhoneMainView.instance changeCurrentView:ShopView.compositeViewDescription]; }]; - + UIAlertAction* laterAction = [UIAlertAction actionWithTitle:@"Later" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { // [alert dismissViewControllerAnimated:FALSE]; }]; - + [alert addAction:buyAction]; [alert addAction:laterAction]; [PhoneMainView.instance presentViewController:alert animated:YES completion:nil]; @@ -534,7 +534,7 @@ - (void) check{ if (!_available) return; if (expiryTime == 0 || checkPeriod == 0) return; - + time_t now = time(NULL); if (now < lastCheck + checkPeriod) return; diff --git a/Classes/ShopTableView.m b/Classes/ShopTableView.m index 112399aa7..374c14a7a 100644 --- a/Classes/ShopTableView.m +++ b/Classes/ShopTableView.m @@ -21,9 +21,26 @@ } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [[UITableViewCell alloc] init]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class)]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle + reuseIdentifier:NSStringFromClass(self.class)]; + } + SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row]; - cell.textLabel.text = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row]; + NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; + [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; + [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; + [numberFormatter setLocale:product.priceLocale]; + NSString *price = [numberFormatter stringFromNumber:product.price]; + + cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price]; + cell.detailTextLabel.text = product.localizedDescription; + cell.detailTextLabel.numberOfLines = 2; + cell.detailTextLabel.minimumScaleFactor = .5; + cell.detailTextLabel.adjustsFontSizeToFitWidth = cell.detailTextLabel.adjustsLetterSpacingToFitWidth = YES; + cell.accessoryType = UITableViewCellAccessoryDetailButton; + [cell setImage:[UIImage imageNamed:@"linphone_logo"]]; return cell; } @@ -31,8 +48,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; - UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; - [LinphoneManager.instance.iapManager purchaseWithID:cell.textLabel.text]; + SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row]; + [LinphoneManager.instance.iapManager purchaseWithID:product.productIdentifier]; } @end diff --git a/Classes/ShopView.h b/Classes/ShopView.h index f6dc827fb..cfe8f14c3 100644 --- a/Classes/ShopView.h +++ b/Classes/ShopView.h @@ -19,17 +19,12 @@ #import +#import "ShopTableView.h" #import "UICompositeView.h" -@interface ShopView : TPMultiLayoutViewController +@interface ShopView : UIViewController -@property(weak, nonatomic) IBOutlet UILabel *accountProductTitle; -@property(weak, nonatomic) IBOutlet UILabel *accountProductDescription; -@property(weak, nonatomic) IBOutlet UILabel *accountProductPrice; -@property(weak, nonatomic) IBOutlet UIButton *accountBuyButton; - -- (IBAction)onLinkTap:(id)sender; +@property(strong, nonatomic) IBOutlet ShopTableView *tableViewController; - (IBAction)onDialerBackClick:(id)sender; -- (IBAction)onPurchaseButtonClick:(id)sender; @end diff --git a/Classes/ShopView.m b/Classes/ShopView.m index 745cad8e5..881b0578e 100644 --- a/Classes/ShopView.m +++ b/Classes/ShopView.m @@ -45,38 +45,14 @@ static UICompositeViewDescription *compositeDescription = nil; return self.class.compositeViewDescription; } -#pragma mark - ViewController Functions - -- (void)viewDidLoad { - InAppProductsManager *aipm = LinphoneManager.instance.iapManager; - NSMutableArray *productsAvailable = aipm.productsAvailable; - if ( [productsAvailable count] > 0){ - SKProduct *product = [productsAvailable objectAtIndex:0]; - [_accountProductTitle setText:product.localizedTitle]; - [_accountProductDescription setText:product.localizedDescription]; - - NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; - [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; - [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; - [numberFormatter setLocale:product.priceLocale]; - NSString *formattedString = [numberFormatter stringFromNumber:product.price]; - [_accountProductPrice setText:formattedString]; - } - [super viewDidLoad]; - +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + [_tableViewController.tableView reloadData]; } - #pragma mark - Action Functions -- (IBAction)onLinkTap:(id)sender { - -} - - (IBAction)onDialerBackClick:(id)sender { [PhoneMainView.instance popToView:DialerView.compositeViewDescription]; } -- (IBAction)onPurchaseButtonClick:(id)sender { - [PhoneMainView.instance popToView:DialerView.compositeViewDescription]; -} @end diff --git a/Classes/SideMenuTableView.m b/Classes/SideMenuTableView.m index 231b80b19..31aae6802 100644 --- a/Classes/SideMenuTableView.m +++ b/Classes/SideMenuTableView.m @@ -34,10 +34,10 @@ // remove separators between empty items, cf // http://stackoverflow.com/questions/1633966/can-i-force-a-uitableview-to-hide-the-separator-between-empty-cells self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; -} + //} -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; + //- (void)viewWillAppear:(BOOL)animated { + // [super viewWillAppear:animated]; _sideMenuEntries = [[NSMutableArray alloc] init]; diff --git a/Resources/assistant_linphone_create.rc b/Resources/assistant_linphone_create.rc index 227344e7c..641a06267 100644 --- a/Resources/assistant_linphone_create.rc +++ b/Resources/assistant_linphone_create.rc @@ -28,6 +28,6 @@ 64 1 ^[a-z0-9+_.\-]*$ - https://sip3.linphone.org:444/wizard.php + https://subscribe.linphone.org:444/wizard.php diff --git a/Resources/assistant_linphone_existing.rc b/Resources/assistant_linphone_existing.rc index 4d9fd9481..3541d3fed 100644 --- a/Resources/assistant_linphone_existing.rc +++ b/Resources/assistant_linphone_existing.rc @@ -28,6 +28,6 @@ 64 1 ^[a-z0-9+_.\-]*$ - https://sip3.linphone.org:444/wizard.php + https://subscribe.linphone.org:444/wizard.php diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 3e755f700..24ae36874 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -29,7 +29,7 @@ enabled=0 paid_account_id=sipAccount_12m #the url of the inapp/account management server, for submitting the receipt and validating the account. -receipt_validation_url=https://www.linphone.org/inapp.php +receipt_validation_url=https://subscribe.linphone.org:444/inapp.php #for future use, to specify the full list of paying services to show in the shop view products_list=sipAccount_12m diff --git a/submodules/linphone b/submodules/linphone index ee50e0e3c..01df9f935 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit ee50e0e3c1863bd7924cdcf3f7fd2eb34c886195 +Subproject commit 01df9f93533bb1526a673ae7c557ae2508747a49