Skip to content

Commit

Permalink
[sms] Fix MFMessageComposeViewController being initialized from non…
Browse files Browse the repository at this point in the history
…-main thread (#8575)
  • Loading branch information
tsapeta committed Jun 1, 2020
1 parent c31c4f3 commit 162a805
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/expo-sms/CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@

### 🐛 Bug fixes

- Fixed rare crashes on iOS caused by `MFMessageComposeViewController` being initialized not from the main thread. ([#8575](https://github.com/expo/expo/pull/8575) by [@tsapeta](https://github.com/tsapeta))

## 8.2.1 — 2020-05-29

*This version does not introduce any user-facing changes.*
Expand Down
15 changes: 9 additions & 6 deletions packages/expo-sms/ios/EXSMS/EXSMSModule.m
Expand Up @@ -21,6 +21,13 @@ @implementation EXSMSModule

UM_EXPORT_MODULE(ExpoSMS);

- (dispatch_queue_t)methodQueue
{
// Everything in this module uses `MFMessageComposeViewController` which is a subclass of UIViewController,
// so everything should be called from main thread.
return dispatch_get_main_queue();
}

- (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
{
_utils = [moduleRegistry getModuleImplementingProtocol:@protocol(UMUtilitiesInterface)];
Expand Down Expand Up @@ -52,7 +59,7 @@ - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry

_resolve = resolve;
_reject = reject;

MFMessageComposeViewController *messageComposeViewController = [[MFMessageComposeViewController alloc] init];
messageComposeViewController.messageComposeDelegate = self;
messageComposeViewController.recipients = addresses;
Expand Down Expand Up @@ -87,11 +94,7 @@ - (void)setModuleRegistry:(UMModuleRegistry *)moduleRegistry
}
}

UM_WEAKIFY(self);
[UMUtilities performSynchronouslyOnMainThread:^{
UM_ENSURE_STRONGIFY(self);
[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];
}];
[self.utils.currentViewController presentViewController:messageComposeViewController animated:YES completion:nil];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
Expand Down

0 comments on commit 162a805

Please sign in to comment.