Remove NSException from RiotShareExtension

Fix some retain cycles and early releases.
This commit is contained in:
Doug 2022-03-11 14:59:57 +00:00 committed by Doug
parent 6fd2f2c3a2
commit bb8f330ca0
3 changed files with 12 additions and 8 deletions

View file

@ -34,6 +34,12 @@
@property (nonatomic, strong) MXKAccount *userAccount;
@property (nonatomic, strong) MXFileStore *fileStore;
/**
An array of rooms that the item is being shared to. This is to maintain a strong ref
to all necessary `MXRoom`s until sharing has completed.
*/
@property (nonatomic, strong) NSMutableArray<MXRoom *> *selectedRooms;
@end
@ -94,17 +100,19 @@
session.crypto.warnOnUnknowDevices = NO; // Do not warn for unknown devices. We have cross-signing now
NSMutableArray<MXRoom *> *rooms = [NSMutableArray array];
self.selectedRooms = [NSMutableArray array];
for (NSString *roomIdentifier in roomIdentifiers) {
MXRoom *room = [MXRoom loadRoomFromStore:self.fileStore withRoomId:roomIdentifier matrixSession:session];
if (room) {
[rooms addObject:room];
[self.selectedRooms addObject:room];
}
}
[self.shareItemSender sendItemsToRooms:rooms success:^{
[self.shareItemSender sendItemsToRooms:self.selectedRooms success:^{
self.selectedRooms = nil;
self.completionCallback(ShareManagerResultFinished);
} failure:^(NSArray<NSError *> *errors) {
self.selectedRooms = nil;
[self showFailureAlert:[VectorL10n roomEventFailedToSend]];
}];

View file

@ -99,10 +99,6 @@
{
[self dismissViewControllerAnimated:true completion:^{
[self.presentingViewController dismissViewControllerAnimated:false completion:nil];
// FIXME: Share extension memory usage increase when launched several times and then crash due to some memory leaks.
// For now, we force the share extension to exit and free memory.
[NSException raise:@"Kill the app extension" format:@"Free memory used by share extension"];
}];
}

View file

@ -35,7 +35,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
@interface ShareItemSender ()
@property (nonatomic, strong, readonly) UIViewController *rootViewController;
@property (nonatomic, weak, readonly) UIViewController *rootViewController;
@property (nonatomic, strong, readonly) ShareExtensionShareItemProvider *shareItemProvider;
@property (nonatomic, strong, readonly) NSMutableArray<NSData *> *pendingImages;