App extension - Improvement: Reduce memory consumption.

Force the ShareExtensionManager to release the primary view controller when the action is completed.

We observed that `dealloc` is called for this view controller when the request is cancelled with error (`cancelRequestWithError`), but it is not called when the request is completed (`completeRequestReturningItems`).
This commit is contained in:
Giom Foret
2017-08-25 11:55:37 +02:00
parent 84f3aefac4
commit be2fe8fea9
6 changed files with 79 additions and 22 deletions
@@ -20,6 +20,8 @@
@interface SharePresentingViewController ()
@property (nonatomic) ShareViewController *shareViewController;
@end
@implementation SharePresentingViewController
@@ -28,21 +30,33 @@
{
[super viewDidLoad];
[ShareExtensionManager sharedManager].shareExtensionContext = self.extensionContext;
ShareExtensionManager *sharedManager = [ShareExtensionManager sharedManager];
sharedManager.primaryViewController = self;
sharedManager.shareExtensionContext = self.extensionContext;
[self presentShareViewController];
}
- (void)destroy
{
if (self.shareViewController)
{
[self.shareViewController destroy];
self.shareViewController = nil;
}
}
- (void)presentShareViewController
{
ShareViewController *shareViewController = [[ShareViewController alloc] init];
self.shareViewController = [[ShareViewController alloc] init];
shareViewController.providesPresentationContextTransitionStyle = YES;
shareViewController.definesPresentationContext = YES;
shareViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
shareViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.shareViewController.providesPresentationContextTransitionStyle = YES;
self.shareViewController.definesPresentationContext = YES;
self.shareViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.shareViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:shareViewController animated:YES completion:nil];
[self presentViewController:self.shareViewController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning