InviteController.m 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "InviteController.h"
  21. #import "AppDelegate.h"
  22. #import <Social/Social.h>
  23. #import "ShareTextActivityItemProvider.h"
  24. #import "ShareUrlActivityItemProvider.h"
  25. #import "ActivityUtil.h"
  26. #import "MyIdentityStore.h"
  27. @implementation InviteController {
  28. }
  29. static InviteController *currentInviteController;
  30. - (void)invite {
  31. ShareTextActivityItemProvider *shareText = [[ShareTextActivityItemProvider alloc] initWithPlaceholderItem:[NSString stringWithFormat:NSLocalizedString(@"invite_facebook_text", @""), [[MyIdentityStore sharedMyIdentityStore] identity]]];
  32. NSMutableArray *activityItems = [[NSMutableArray alloc] initWithArray:@[shareText]];
  33. UIActivityViewController* activityViewController = [ActivityUtil activityViewControllerWithActivityItems:activityItems applicationActivities:nil];
  34. if (SYSTEM_IS_IPAD) {
  35. activityViewController.popoverPresentationController.sourceView = self.parentViewController.view;
  36. activityViewController.popoverPresentationController.sourceRect = _rect;
  37. }
  38. [self.shareViewController presentViewController:activityViewController animated:YES completion:nil];
  39. }
  40. - (void)presentMailComposer {
  41. MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
  42. [mailComposer setSubject:NSLocalizedString(@"invite_email_subject", nil)];
  43. [mailComposer setMessageBody:[NSString stringWithFormat:NSLocalizedString(@"invite_email_body", @""), [[MyIdentityStore sharedMyIdentityStore] identity]] isHTML:NO];
  44. mailComposer.mailComposeDelegate = self;
  45. [self.parentViewController presentViewController:mailComposer animated:YES completion:nil];
  46. /* Trick to avoid getting deallocated (since delegates are not retained) */
  47. currentInviteController = self;
  48. }
  49. - (void)presentMessageComposer {
  50. MFMessageComposeViewController *smsComposer = [[MFMessageComposeViewController alloc] init];
  51. [smsComposer setBody:[NSString stringWithFormat:NSLocalizedString(@"invite_sms_body", @""), [[MyIdentityStore sharedMyIdentityStore] identity]]];
  52. smsComposer.messageComposeDelegate = self;
  53. [self.parentViewController presentViewController:smsComposer animated:YES completion:nil];
  54. /* Trick to avoid getting deallocated (since delegates are not retained) */
  55. currentInviteController = self;
  56. }
  57. #pragma mark - Mail composer delegate
  58. - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
  59. [self.parentViewController dismissViewControllerAnimated:YES completion:nil];
  60. currentInviteController = nil;
  61. }
  62. #pragma mark - Message composer delegate
  63. - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
  64. [self.parentViewController dismissViewControllerAnimated:YES completion:nil];
  65. currentInviteController = nil;
  66. }
  67. @end