From 81a0cff0f57b11abaacd9c5adf1302d889d37d88 Mon Sep 17 00:00:00 2001 From: Aleksey Belouosv Date: Wed, 21 Aug 2019 14:17:23 +0300 Subject: [PATCH] [iOS] show authorization dialog before subscription screen --- .../BookmarksSubscriptionViewController.swift | 56 ++++++++++--------- iphone/Maps/Bridging-Header.h | 1 + iphone/Maps/Common/WebViewController.mm | 2 +- iphone/Maps/Maps.xcodeproj/project.pbxproj | 4 ++ .../AuthorizationViewController.swift | 21 ++++--- ...oneNumberAuthorizationViewController.swift | 22 ++++++++ 6 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift diff --git a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift index 8885963ccc..aec31b9799 100644 --- a/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift +++ b/iphone/Maps/Bookmarks/Catalog/BookmarksSubscriptionViewController.swift @@ -134,41 +134,47 @@ class BookmarksSubscriptionViewController: MWMViewController { } @IBAction func onContinue(_ sender: UIButton) { - loadingView.isHidden = false - MWMBookmarksManager.shared().ping { [weak self] (success) in - guard success else { - self?.loadingView.isHidden = true - let errorDialog = BookmarksSubscriptionFailViewController { [weak self] in - self?.dismiss(animated: true) + signup(anchor: sender) { [weak self] success in + guard success else { return } + self?.loadingView.isHidden = false + MWMBookmarksManager.shared().ping { success in + guard success else { + self?.loadingView.isHidden = true + let errorDialog = BookmarksSubscriptionFailViewController { [weak self] in + self?.dismiss(animated: true) + } + self?.present(errorDialog, animated: true) + return } - self?.present(errorDialog, animated: true) - return - } - guard let subscription = self?.selectedSubscription else { - return + guard let subscription = self?.selectedSubscription else { + return + } + + InAppPurchase.bookmarksSubscriptionManager.subscribe(to: subscription) } - - InAppPurchase.bookmarksSubscriptionManager.subscribe(to: subscription) } Statistics.logEvent(kStatInappPay, withParameters: [kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) } @IBAction func onRestore(_ sender: UIButton) { - loadingView.isHidden = false Statistics.logEvent(kStatInappRestore, withParameters: [kStatPurchase: MWMPurchaseManager.bookmarksSubscriptionServerId()]) - InAppPurchase.bookmarksSubscriptionManager.restore { [weak self] result in - self?.loadingView.isHidden = true - let alertText: String - switch result { - case .valid: - alertText = L("restore_success_alert") - case .notValid: - alertText = L("restore_no_subscription_alert") - case .serverError, .authError: - alertText = L("restore_error_alert") + signup(anchor: sender) { [weak self] (success) in + guard success else { return } + self?.loadingView.isHidden = false + InAppPurchase.bookmarksSubscriptionManager.restore { result in + self?.loadingView.isHidden = true + let alertText: String + switch result { + case .valid: + alertText = L("restore_success_alert") + case .notValid: + alertText = L("restore_no_subscription_alert") + case .serverError, .authError: + alertText = L("restore_error_alert") + } + MWMAlertViewController.activeAlert().presentInfoAlert(L("restore_subscription"), text: alertText) } - MWMAlertViewController.activeAlert().presentInfoAlert(L("restore_subscription"), text: alertText) } } diff --git a/iphone/Maps/Bridging-Header.h b/iphone/Maps/Bridging-Header.h index feaf1d83d1..60222077a5 100644 --- a/iphone/Maps/Bridging-Header.h +++ b/iphone/Maps/Bridging-Header.h @@ -45,6 +45,7 @@ #import "MWMKeyboard.h" #import "MWMLocationManager.h" #import "MWMMapWidgetsHelper.h" +#import "MWMNavigationController.h" #import "MWMNavigationDashboardEntity.h" #import "MWMNavigationDashboardManager.h" #import "MWMNoMapsViewController.h" diff --git a/iphone/Maps/Common/WebViewController.mm b/iphone/Maps/Common/WebViewController.mm index 1b73d92942..d87706d9d1 100644 --- a/iphone/Maps/Common/WebViewController.mm +++ b/iphone/Maps/Common/WebViewController.mm @@ -50,7 +50,7 @@ - (instancetype)initWithAuthURL:(NSURL *)url onSuccessAuth:(MWMStringBlock)success onFailure:(MWMVoidBlock)failure { - self = [super init]; + self = [super initWithNibName:nil bundle:nil]; if (self) { _m_url = url; diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 851ef80717..d7c01b1ea3 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -456,6 +456,7 @@ 47F6E51721FB3C51004580CA /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F6E51621FB3C51004580CA /* Notifications.swift */; }; 47F86CFF20C936FC00FEE291 /* TabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F86CFE20C936FC00FEE291 /* TabView.swift */; }; 47F86D0120C93D8D00FEE291 /* TabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F86D0020C93D8D00FEE291 /* TabViewController.swift */; }; + 47FA14D1230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */; }; 4A300ED51C6DCFD400140018 /* countries-strings in Resources */ = {isa = PBXBuildFile; fileRef = 4A300ED31C6DCFD400140018 /* countries-strings */; }; 56C74C391C74A3BC00B71B9F /* MWMInputEmailValidator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34ABA62F1C2D58F300FE1BEC /* MWMInputEmailValidator.mm */; }; 56EE14D11FE804550036F20C /* libtransit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 56EE14D21FE804550036F20C /* libtransit.a */; }; @@ -1563,6 +1564,7 @@ 47F6E51621FB3C51004580CA /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = ""; }; 47F86CFE20C936FC00FEE291 /* TabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabView.swift; sourceTree = ""; }; 47F86D0020C93D8D00FEE291 /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = ""; }; + 47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberAuthorizationViewController.swift; sourceTree = ""; }; 4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_dark.bin; path = ../../data/drules_proto_dark.bin; sourceTree = ""; }; 4A23D1561B8B4DD700D4EB6F /* drules_proto_clear.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_clear.bin; path = ../../data/drules_proto_clear.bin; sourceTree = ""; }; 4A23D1571B8B4DD700D4EB6F /* resources-6plus_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-6plus_clear"; path = "../../data/resources-6plus_clear"; sourceTree = ""; }; @@ -3300,6 +3302,7 @@ 34BBD6661F8273350070CA50 /* AuthorizationViewController.xib */, 3408963C1F83CEDE00BC7117 /* MWMAuthorizationViewModel.h */, 3408963D1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm */, + 47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */, ); path = Authorization; sourceTree = ""; @@ -5246,6 +5249,7 @@ F6E2FD8F1E097BA00083EBEC /* MWMNoMapsViewController.mm in Sources */, F63AF50B1EA6213F00A1DB98 /* FilterRatingCell.swift in Sources */, 34D3B0421E389D05004100F9 /* MWMEditorTextTableViewCell.mm in Sources */, + 47FA14D1230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift in Sources */, 340708651F2905A500029ECC /* NavigationInfoArea.swift in Sources */, 34AB666B1FC5AA330078E451 /* TransportTransitCell.swift in Sources */, 3404163C1E7BDFE000E2B6D6 /* PhotosViewController.swift in Sources */, diff --git a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift index 149079efa6..5f0826d911 100644 --- a/iphone/Maps/UI/Authorization/AuthorizationViewController.swift +++ b/iphone/Maps/UI/Authorization/AuthorizationViewController.swift @@ -99,17 +99,16 @@ final class AuthorizationViewController: MWMViewController { } @IBAction private func phoneSignIn() { - dismiss(animated: true) { - let url = ViewModel.phoneAuthURL()! - let wv = WebViewController(authURL: url, onSuccessAuth: { (token: String?) in - self.process(token: token!, type: .phone) - }, onFailure: { - self.process(error: NSError(domain: kMapsmeErrorDomain, code: 0), type: .phone) - self.errorHandler?(.cancelled) - }) - - MapViewController.topViewController().navigationController?.pushViewController(wv!, animated: true) - } + let authVC = PhoneNumberAuthorizationViewController(success: { [unowned self] token in + self.dismiss(animated: true) + self.process(token: token!, type: .phone) + }, failure: { [unowned self] in + self.dismiss(animated: true) + self.process(error: NSError(domain: kMapsmeErrorDomain, code: 0), type: .phone) + self.errorHandler?(.cancelled) + }) + let navVC = MWMNavigationController(rootViewController: authVC) + self.present(navVC, animated: true) } @IBOutlet private weak var phoneSignInButton: UIButton! { diff --git a/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift b/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift new file mode 100644 index 0000000000..3605e8b103 --- /dev/null +++ b/iphone/Maps/UI/Authorization/PhoneNumberAuthorizationViewController.swift @@ -0,0 +1,22 @@ +class PhoneNumberAuthorizationViewController: WebViewController { + var failure: MWMVoidBlock? + + init(success: @escaping MWMStringBlock, failure: @escaping MWMVoidBlock) { + super.init(authURL: MWMAuthorizationViewModel.phoneAuthURL()!, onSuccessAuth: success, onFailure: failure)! + self.failure = failure + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(onCancel(_:))) + navigationItem.leftBarButtonItem = cancelButton + } + + @objc func onCancel(_ sender: UIBarButtonItem) { + failure?() + } +}