Skip to content

Commit

Permalink
IOS-9301 Fix crash on MasterKeyViewController.dispatchOnViewDidLoadAc…
Browse files Browse the repository at this point in the history
…tion()

(cherry picked from commit 727eedadf6b1873abd9baed266bcfa4233195c00)
  • Loading branch information
gmagpayo committed Nov 8, 2024
1 parent c53b39b commit 5ba4abc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -15,4 +16,8 @@ final class MockRecoveryKeyViewRouter: RecoveryKeyViewRouting {
func showSecurityLink() {
showSecurityLink_calledTimes += 1
}

func presentView() {
presentView_calledTimes += 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions iMEGA/Utils/MEGALinks/MEGALinkManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down

0 comments on commit 5ba4abc

Please sign in to comment.