From 4686dc82568729d1bb14b9395e35b6de38493b30 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 14:15:12 -0400 Subject: [PATCH] contact behavior --- .../ActionHandling/MVMCoreActionHandler.m | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index a09eb6a..39d43ca 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -274,9 +274,10 @@ NSString * const KeyActionTypeOpen = @"openPage"; contact.phoneNumbers = @[phone]; if ([approach isEqualToString:KeyAdd]) { - // Nothing for now. [MVMCoreDispatchUtility performBlockOnMainThread:^{ CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + // Setting to accessibilityValue as a workaround to pass data via the delegate function. + [controller setAccessibilityValue:MDN]; controller.delegate = weakSelf; [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; @@ -395,22 +396,27 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact { - CNContactStore *store = [[CNContactStore alloc] init]; - CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; - CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:@"1234567890"]; - CNLabeledValue * labelValue = [[CNLabeledValue alloc]initWithLabel:CNLabelOther value:number]; - NSMutableArray *phoneNumbers = [NSMutableArray new]; - [phoneNumbers addObject:labelValue]; - [phoneNumbers addObjectsFromArray:existingContact.phoneNumbers]; - existingContact.phoneNumbers = phoneNumbers; + // This is a means to pass the data to this delegate function. + NSString *MDN = picker.accessibilityValue; - CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact]; - controller.contactStore = store; - controller.delegate = self; - - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; - }]; + if (MDN) { + CNContactStore *store = [[CNContactStore alloc] init]; + CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; + CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:MDN]; + CNLabeledValue * labelValue = [[CNLabeledValue alloc]initWithLabel:CNLabelOther value:number]; + NSMutableArray *phoneNumbers = [NSMutableArray new]; + [phoneNumbers addObject:labelValue]; + [phoneNumbers addObjectsFromArray:existingContact.phoneNumbers]; + existingContact.phoneNumbers = phoneNumbers; + + CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact]; + controller.contactStore = store; + controller.delegate = self; + + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; + }]; + } } #pragma mark - Open URL