Skip to content

Commit 5ba4abc

Browse files
committed
IOS-9301 Fix crash on MasterKeyViewController.dispatchOnViewDidLoadAction()
(cherry picked from commit 727eeda)
1 parent c53b39b commit 5ba4abc

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

MEGAUnitTests/Mocks/Router/MockRecoveryKeyViewRouter.swift

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
final class MockRecoveryKeyViewRouter: RecoveryKeyViewRouting {
44
private(set) var showSecurityLink_calledTimes = 0
5+
private(set) var presentView_calledTimes = 0
56
private let _recoveryKeyViewController: UIViewController?
67

78
init(recoveryKeyViewController: UIViewController? = nil) {
@@ -15,4 +16,8 @@ final class MockRecoveryKeyViewRouter: RecoveryKeyViewRouting {
1516
func showSecurityLink() {
1617
showSecurityLink_calledTimes += 1
1718
}
19+
20+
func presentView() {
21+
presentView_calledTimes += 1
22+
}
1823
}

iMEGA/My Account/Settings/Security/ViewModel/RecoveryKeyViewRouter.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import MEGASDKRepo
55
protocol RecoveryKeyViewRouting: Routing {
66
var recoveryKeyViewController: UIViewController? { get }
77
func showSecurityLink()
8+
func presentView()
89
}
910

1011
final class RecoveryKeyViewRouter: RecoveryKeyViewRouting {
1112
private weak var baseViewController: UIViewController?
1213
private weak var navigationController: UINavigationController?
14+
private weak var presenter: UIViewController?
1315

1416
private let securityURLLink = NSURL(string: "https://mega.nz/security")
1517

16-
init(navigationController: UINavigationController?) {
18+
init(
19+
navigationController: UINavigationController? = nil,
20+
presenter: UIViewController? = nil
21+
) {
1722
self.navigationController = navigationController
23+
self.presenter = presenter
1824
}
1925

2026
func build() -> UIViewController {
@@ -38,6 +44,17 @@ final class RecoveryKeyViewRouter: RecoveryKeyViewRouting {
3844
navigationController.pushViewController(build(), animated: true)
3945
}
4046

47+
func presentView() {
48+
guard let presenter else {
49+
MEGALogDebug("[Recovery Key] No presenter UIViewController passed on RecoveryKeyViewRouter")
50+
return
51+
}
52+
53+
let navigationController = MEGANavigationController(rootViewController: build())
54+
navigationController.addRightCancelButton()
55+
presenter.present(navigationController, animated: true)
56+
}
57+
4158
var recoveryKeyViewController: UIViewController? {
4259
baseViewController
4360
}

iMEGA/Utils/MEGALinks/MEGALinkManager+Additions.swift

+5
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ extension MEGALinkManager: MEGALinkManagerProtocol {
272272
guard let mainTabBar = UIApplication.mainTabBarRootViewController() as? MainTabBarController else { return }
273273
mainTabBar.showCameraUploadsSettings()
274274
}
275+
276+
@objc class func showBackupLinkView() {
277+
guard Helper.hasSession_alertIfNot() else { return }
278+
RecoveryKeyViewRouter(presenter: UIApplication.mnz_visibleViewController()).presentView()
279+
}
275280
}
276281

277282
// MARK: - Ads

iMEGA/Utils/MEGALinks/MEGALinkManager.m

-10
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,6 @@ + (void)showFolderLinkView {
647647
[self presentViewControllerWithAds:folderNavigationController adsSlotViewController:folderlinkVC presentationStyle:UIModalPresentationFullScreen];
648648
}
649649

650-
+ (void)showBackupLinkView {
651-
if ([Helper hasSession_alertIfNot]) {
652-
MasterKeyViewController *masterKeyVC = [[UIStoryboard storyboardWithName:@"Settings" bundle:nil] instantiateViewControllerWithIdentifier:@"MasterKeyViewControllerID"];
653-
MEGANavigationController *navigationController = [[MEGANavigationController alloc] initWithRootViewController:masterKeyVC];
654-
[navigationController addRightCancelButton];
655-
656-
[UIApplication.mnz_visibleViewController presentViewController:navigationController animated:YES completion:nil];
657-
}
658-
}
659-
660650
+ (void)showContactRequestsView {
661651
if ([Helper hasSession_alertIfNot]) {
662652
ContactRequestsViewController *contactsRequestsVC = [[UIStoryboard storyboardWithName:@"Contacts" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactsRequestsViewControllerID"];

0 commit comments

Comments
 (0)