Fix retain cycle in settings views.

pull/1/head
Matthew Chen 7 years ago
parent f40b81ca4c
commit 56fe3663e6

@ -248,7 +248,8 @@
- (OWSTableItem *)destructiveButtonItemWithTitle:(NSString *)title selector:(SEL)selector color:(UIColor *)color - (OWSTableItem *)destructiveButtonItemWithTitle:(NSString *)title selector:(SEL)selector color:(UIColor *)color
{ {
return [OWSTableItem __weak AppSettingsViewController *weakSelf = self;
return [OWSTableItem
itemWithCustomCellBlock:^{ itemWithCustomCellBlock:^{
UITableViewCell *cell = [OWSTableItem newCell]; UITableViewCell *cell = [OWSTableItem newCell];
cell.preservesSuperviewLayoutMargins = YES; cell.preservesSuperviewLayoutMargins = YES;
@ -260,7 +261,7 @@
font:[OWSFlatButton fontForHeight:kButtonHeight] font:[OWSFlatButton fontForHeight:kButtonHeight]
titleColor:[UIColor whiteColor] titleColor:[UIColor whiteColor]
backgroundColor:color backgroundColor:color
target:self target:weakSelf
selector:selector]; selector:selector];
[cell.contentView addSubview:button]; [cell.contentView addSubview:button];
[button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight];
@ -423,6 +424,8 @@
- (void)showDeleteAccountUI:(BOOL)isRegistered - (void)showDeleteAccountUI:(BOOL)isRegistered
{ {
__weak AppSettingsViewController *weakSelf = self;
UIAlertController *alertController = UIAlertController *alertController =
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"") [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TITLE", @"")
message:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TEXT", @"") message:NSLocalizedString(@"CONFIRM_ACCOUNT_DESTRUCTION_TEXT", @"")
@ -430,7 +433,7 @@
[alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"") [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"PROCEED_BUTTON", @"")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self deleteAccount:isRegistered]; [weakSelf deleteAccount:isRegistered];
}]]; }]];
[alertController addAction:[OWSAlerts cancelAction]]; [alertController addAction:[OWSAlerts cancelAction]];

@ -287,7 +287,8 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[self profileCompletedOrSkipped]; [self profileCompletedOrSkipped];
return; return;
} }
__weak ProfileViewController *weakSelf = self;
UIAlertController *controller = [UIAlertController UIAlertController *controller = [UIAlertController
alertControllerWithTitle: alertControllerWithTitle:
NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_TITLE", NSLocalizedString(@"NEW_GROUP_VIEW_UNSAVED_CHANGES_TITLE",
@ -301,7 +302,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
@"The label for the 'discard' button in alerts and action sheets.") @"The label for the 'discard' button in alerts and action sheets.")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self profileCompletedOrSkipped]; [weakSelf profileCompletedOrSkipped];
}]]; }]];
[controller addAction:[OWSAlerts cancelAction]]; [controller addAction:[OWSAlerts cancelAction]];
[self presentViewController:controller animated:YES completion:nil]; [self presentViewController:controller animated:YES completion:nil];
@ -388,7 +389,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
canCancel:NO canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
[OWSProfileManager.sharedManager updateLocalProfileName:normalizedProfileName [OWSProfileManager.sharedManager updateLocalProfileName:normalizedProfileName
avatarImage:self.avatar avatarImage:weakSelf.avatar
success:^{ success:^{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{ [modalActivityIndicator dismissWithCompletion:^{
@ -425,6 +426,9 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
{ {
OWSLogVerbose(@""); OWSLogVerbose(@"");
[self checkCanImportBackup];
return;
// Dismiss this view. // Dismiss this view.
switch (self.profileViewMode) { switch (self.profileViewMode) {
case ProfileViewMode_AppSettings: case ProfileViewMode_AppSettings:
@ -467,6 +471,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
{ {
OWSLogVerbose(@""); OWSLogVerbose(@"");
__weak ProfileViewController *weakSelf = self;
[OWSBackup.sharedManager [OWSBackup.sharedManager
checkCanImportBackup:^(BOOL value) { checkCanImportBackup:^(BOOL value) {
OWSLogInfo(@"has backup available for import? %d", value); OWSLogInfo(@"has backup available for import? %d", value);
@ -474,13 +479,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
if (value) { if (value) {
[OWSBackup.sharedManager setHasPendingRestoreDecision:YES]; [OWSBackup.sharedManager setHasPendingRestoreDecision:YES];
[self showBackupRestoreView]; [weakSelf showBackupRestoreView];
} else { } else {
[self showHomeView]; [weakSelf showHomeView];
} }
} }
failure:^(NSError *error) { failure:^(NSError *error) {
[self showBackupCheckFailedAlert]; [weakSelf showBackupCheckFailedAlert];
}]; }];
} }
@ -488,6 +493,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
{ {
OWSLogVerbose(@""); OWSLogVerbose(@"");
__weak ProfileViewController *weakSelf = self;
UIAlertController *controller = [UIAlertController UIAlertController *controller = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE", alertControllerWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_FAILED_TITLE",
@"Title for alert shown when the app failed to check for an existing backup.") @"Title for alert shown when the app failed to check for an existing backup.")
@ -498,13 +504,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil) [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"REGISTER_FAILED_TRY_AGAIN", nil)
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self checkCanImportBackup]; [weakSelf checkCanImportBackup];
}]]; }]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE", [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CHECK_FOR_BACKUP_DO_NOT_RESTORE",
@"The label for the 'do not restore backup' button.") @"The label for the 'do not restore backup' button.")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self showHomeView]; [weakSelf showHomeView];
}]]; }]];
[self presentViewController:controller animated:YES completion:nil]; [self presentViewController:controller animated:YES completion:nil];
} }

Loading…
Cancel
Save