forked from organicmaps/organicmaps
[iOS] show authorization dialog before subscription screen
This commit is contained in:
parent
9a5e96db79
commit
81a0cff0f5
6 changed files with 69 additions and 37 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = "<group>"; };
|
||||
47F86CFE20C936FC00FEE291 /* TabView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabView.swift; sourceTree = "<group>"; };
|
||||
47F86D0020C93D8D00FEE291 /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = "<group>"; };
|
||||
47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberAuthorizationViewController.swift; sourceTree = "<group>"; };
|
||||
4A00DBDE1AB704C400113624 /* drules_proto_dark.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_dark.bin; path = ../../data/drules_proto_dark.bin; sourceTree = "<group>"; };
|
||||
4A23D1561B8B4DD700D4EB6F /* drules_proto_clear.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = drules_proto_clear.bin; path = ../../data/drules_proto_clear.bin; sourceTree = "<group>"; };
|
||||
4A23D1571B8B4DD700D4EB6F /* resources-6plus_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-6plus_clear"; path = "../../data/resources-6plus_clear"; sourceTree = "<group>"; };
|
||||
|
@ -3300,6 +3302,7 @@
|
|||
34BBD6661F8273350070CA50 /* AuthorizationViewController.xib */,
|
||||
3408963C1F83CEDE00BC7117 /* MWMAuthorizationViewModel.h */,
|
||||
3408963D1F83CEDE00BC7117 /* MWMAuthorizationViewModel.mm */,
|
||||
47FA14D0230D52FC003DA979 /* PhoneNumberAuthorizationViewController.swift */,
|
||||
);
|
||||
path = Authorization;
|
||||
sourceTree = "<group>";
|
||||
|
@ -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 */,
|
||||
|
|
|
@ -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! {
|
||||
|
|
|
@ -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?()
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue