From f5613644a0079400eb3610e12e9b2b689884e7de Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 11:41:49 -0400 Subject: [PATCH] create is working now. --- .../ActionHandling/MVMCoreActionHandler.m | 65 ++++++++++--------- .../ActionType/ActionContactModel.swift | 48 +------------- 2 files changed, 35 insertions(+), 78 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 1165aec..a09eb6a 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -263,36 +263,40 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { __weak typeof(self) weakSelf = self; - CNContactStore *store = [[CNContactStore alloc] init]; - CNMutableContact *mutContact = [[CNMutableContact alloc] init]; NSString *MDN = [actionInformation string:KeyCallNumber]; - NSString *approach = [actionInformation stringForKey:@"approach"]; - CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; - mutContact.phoneNumbers = @[phone]; - - if ([approach isEqualToString:KeyAdd]) { - // Nothing for now. - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; - controller.delegate = weakSelf; - - - [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; - }]; + if (MDN) { + CNMutableContact *contact = [[CNMutableContact alloc] init]; + NSString *approach = [actionInformation stringForKey:@"approach"]; - } else if ([approach isEqualToString:KeyCreate]) { - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - CNContactViewController *controller = [[CNContactViewController alloc] init]; - controller.contactStore = store; - controller.delegate = weakSelf; - - mutContact.givenName = [actionInformation string:@"firstName"]; - mutContact.familyName = [actionInformation string:@"lastName"]; - - [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; - }]; + CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; + contact.phoneNumbers = @[phone]; + + if ([approach isEqualToString:KeyAdd]) { + // Nothing for now. + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + controller.delegate = weakSelf; + + [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; + }]; + } else if ([approach isEqualToString:KeyCreate]) { + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + contact.givenName = [actionInformation string:@"firstName"]; + contact.familyName = [actionInformation string:@"lastName"]; + + CNContactStore *store = [[CNContactStore alloc] init]; + CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:contact]; + controller.contactStore = store; + controller.delegate = weakSelf; + + UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: controller]; + navigationController.modalPresentationStyle = UIModalPresentationPageSheet; + + [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; + }]; + } } } @@ -376,7 +380,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; #pragma mark - CNContactViewControllerDelegate - (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(CNContact *)contact { - [[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController]; } @@ -395,13 +398,13 @@ NSString * const KeyActionTypeOpen = @"openPage"; CNContactStore *store = [[CNContactStore alloc] init]; CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:@"1234567890"]; - CNLabeledValue * labelValue = [[CNLabeledValue alloc]initWithLabel:CNLabelPhoneNumberMobile value:number]; + 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]; + CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact]; controller.contactStore = store; controller.delegate = self; @@ -410,7 +413,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; } -#pragma mark - open url functions +#pragma mark - Open URL - (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -496,7 +499,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES]; } -#pragma mark - Default Action Protocol Functions +#pragma mark - Default Action Protocol + (void)defaultLogAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject{ // Currently no default log action but this will eventually be server driven. diff --git a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift index e5f1b38..1fee221 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift @@ -9,7 +9,7 @@ import ContactsUI -@objcMembers public class ActionContactModel: ActionModelProtocol {//NSObject, ActionModelProtocol { +@objcMembers public class ActionContactModel: ActionModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -37,49 +37,3 @@ import ContactsUI self.analyticsData = analyticsData } } - -// MARK: - CNContactViewControllerDelegate -//extension ActionContactModel: CNContactViewControllerDelegate { -// -// public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) { -// -// MVMCoreNavigationHandler.shared()?.removeCurrentViewController() -// } -// -// public func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool { -// true -// } -//} -/* -// MARK: - CNContactPickerDelegate -extension ActionContactModel: CNContactPickerDelegate { - - func contactPickerDidCancel(_ picker: CNContactPickerViewController) { - MVMCoreNavigationHandler.shared().removeCurrentViewController() - } - - func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) { - - let store = CNContactStore() - let existingContact = contact as? CNMutableContact - let number = CNPhoneNumber(stringValue: "1234567890") - let labelValue = CNLabeledValue(label: CNLabelPhoneNumberMobile, value: number) - var phoneNumbers: [CNLabeledValue]? = [] - phoneNumbers?.append(labelValue) - if let phoneNumbers1 = existingContact?.phoneNumbers { - phoneNumbers?.append(contentsOf: phoneNumbers1) - } - if let phoneNumbers = phoneNumbers { - existingContact?.phoneNumbers = phoneNumbers - } - let controller = CNContactViewController(forNewContact: existingContact) - - controller.contactStore = store - controller.delegate = self - - MVMCoreDispatchUtility.performBlock(onMainThread: { - MVMCoreNavigationHandler.shared().present(controller, animated: true) - }) - } -} -*/