From 5ba4abcb19a60c274be00c89bd8671a6f212f185 Mon Sep 17 00:00:00 2001 From: Glazel Magpayo Date: Fri, 8 Nov 2024 11:35:21 +0800 Subject: [PATCH] IOS-9301 Fix crash on MasterKeyViewController.dispatchOnViewDidLoadAction() (cherry picked from commit 727eedadf6b1873abd9baed266bcfa4233195c00) --- .../Router/MockRecoveryKeyViewRouter.swift | 5 +++++ .../ViewModel/RecoveryKeyViewRouter.swift | 19 ++++++++++++++++++- .../MEGALinks/MEGALinkManager+Additions.swift | 5 +++++ iMEGA/Utils/MEGALinks/MEGALinkManager.m | 10 ---------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift b/MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift index e684372e0..82aba3df4 100644 --- a/MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift +++ b/MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift @@ -2,6 +2,7 @@ final class MockRecoveryKeyViewRouter: RecoveryKeyViewRouting { private(set) var showSecurityLink_calledTimes = 0 + private(set) var presentView_calledTimes = 0 private let _recoveryKeyViewController: UIViewController? init(recoveryKeyViewController: UIViewController? = nil) { @@ -15,4 +16,8 @@ final class MockRecoveryKeyViewRouter: RecoveryKeyViewRouting { func showSecurityLink() { showSecurityLink_calledTimes += 1 } + + func presentView() { + presentView_calledTimes += 1 + } } diff --git a/iMEGA/My Account/Settings/Security/ViewModel/RecoveryKeyViewRouter.swift b/iMEGA/My Account/Settings/Security/ViewModel/RecoveryKeyViewRouter.swift index 014855206..4edef0c1e 100644 --- a/iMEGA/My Account/Settings/Security/ViewModel/RecoveryKeyViewRouter.swift +++ b/iMEGA/My Account/Settings/Security/ViewModel/RecoveryKeyViewRouter.swift @@ -5,16 +5,22 @@ import MEGASDKRepo protocol RecoveryKeyViewRouting: Routing { var recoveryKeyViewController: UIViewController? { get } func showSecurityLink() + func presentView() } final class RecoveryKeyViewRouter: RecoveryKeyViewRouting { private weak var baseViewController: UIViewController? private weak var navigationController: UINavigationController? + private weak var presenter: UIViewController? private let securityURLLink = NSURL(string: "https://mega.nz/security") - init(navigationController: UINavigationController?) { + init( + navigationController: UINavigationController? = nil, + presenter: UIViewController? = nil + ) { self.navigationController = navigationController + self.presenter = presenter } func build() -> UIViewController { @@ -38,6 +44,17 @@ final class RecoveryKeyViewRouter: RecoveryKeyViewRouting { navigationController.pushViewController(build(), animated: true) } + func presentView() { + guard let presenter else { + MEGALogDebug("[Recovery Key] No presenter UIViewController passed on RecoveryKeyViewRouter") + return + } + + let navigationController = MEGANavigationController(rootViewController: build()) + navigationController.addRightCancelButton() + presenter.present(navigationController, animated: true) + } + var recoveryKeyViewController: UIViewController? { baseViewController } diff --git a/iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift b/iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift index ac5415932..39b3dc527 100644 --- a/iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift +++ b/iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift @@ -272,6 +272,11 @@ extension MEGALinkManager: MEGALinkManagerProtocol { guard let mainTabBar = UIApplication.mainTabBarRootViewController() as? MainTabBarController else { return } mainTabBar.showCameraUploadsSettings() } + + @objc class func showBackupLinkView() { + guard Helper.hasSession_alertIfNot() else { return } + RecoveryKeyViewRouter(presenter: UIApplication.mnz_visibleViewController()).presentView() + } } // MARK: - Ads diff --git a/iMEGA/Utils/MEGALinks/MEGALinkManager.m b/iMEGA/Utils/MEGALinks/MEGALinkManager.m index 583a41cd0..87f302db1 100644 --- a/iMEGA/Utils/MEGALinks/MEGALinkManager.m +++ b/iMEGA/Utils/MEGALinks/MEGALinkManager.m @@ -647,16 +647,6 @@ + (void)showFolderLinkView { [self presentViewControllerWithAds:folderNavigationController adsSlotViewController:folderlinkVC presentationStyle:UIModalPresentationFullScreen]; } -+ (void)showBackupLinkView { - if ([Helper hasSession_alertIfNot]) { - MasterKeyViewController *masterKeyVC = [[UIStoryboard storyboardWithName:@"Settings" bundle:nil] instantiateViewControllerWithIdentifier:@"MasterKeyViewControllerID"]; - MEGANavigationController *navigationController = [[MEGANavigationController alloc] initWithRootViewController:masterKeyVC]; - [navigationController addRightCancelButton]; - - [UIApplication.mnz_visibleViewController presentViewController:navigationController animated:YES completion:nil]; - } -} - + (void)showContactRequestsView { if ([Helper hasSession_alertIfNot]) { ContactRequestsViewController *contactsRequestsVC = [[UIStoryboard storyboardWithName:@"Contacts" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactsRequestsViewControllerID"];