create is working now.

This commit is contained in:
Kevin G Christiano 2021-04-07 11:41:49 -04:00
parent dcc8567401
commit f5613644a0
2 changed files with 35 additions and 78 deletions

View File

@ -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<CNLabeledValue *> *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.

View File

@ -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)
})
}
}
*/