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 { - (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
CNContactStore *store = [[CNContactStore alloc] init];
CNMutableContact *mutContact = [[CNMutableContact alloc] init];
NSString *MDN = [actionInformation string:KeyCallNumber]; NSString *MDN = [actionInformation string:KeyCallNumber];
NSString *approach = [actionInformation stringForKey:@"approach"];
CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; if (MDN) {
mutContact.phoneNumbers = @[phone]; CNMutableContact *contact = [[CNMutableContact alloc] init];
NSString *approach = [actionInformation stringForKey:@"approach"];
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]) { CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]];
[MVMCoreDispatchUtility performBlockOnMainThread:^{ contact.phoneNumbers = @[phone];
CNContactViewController *controller = [[CNContactViewController alloc] init];
controller.contactStore = store; if ([approach isEqualToString:KeyAdd]) {
controller.delegate = weakSelf; // Nothing for now.
[MVMCoreDispatchUtility performBlockOnMainThread:^{
mutContact.givenName = [actionInformation string:@"firstName"]; CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init];
mutContact.familyName = [actionInformation string:@"lastName"]; controller.delegate = weakSelf;
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; [[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 #pragma mark - CNContactViewControllerDelegate
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(CNContact *)contact { - (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(CNContact *)contact {
[[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController]; [[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController];
} }
@ -395,13 +398,13 @@ NSString * const KeyActionTypeOpen = @"openPage";
CNContactStore *store = [[CNContactStore alloc] init]; CNContactStore *store = [[CNContactStore alloc] init];
CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy];
CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:@"1234567890"]; 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]; NSMutableArray<CNLabeledValue *> *phoneNumbers = [NSMutableArray new];
[phoneNumbers addObject:labelValue]; [phoneNumbers addObject:labelValue];
[phoneNumbers addObjectsFromArray:existingContact.phoneNumbers]; [phoneNumbers addObjectsFromArray:existingContact.phoneNumbers];
existingContact.phoneNumbers = phoneNumbers; existingContact.phoneNumbers = phoneNumbers;
CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact];
CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact];
controller.contactStore = store; controller.contactStore = store;
controller.delegate = self; 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 { - (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]; [[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{ + (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. // Currently no default log action but this will eventually be server driven.

View File

@ -9,7 +9,7 @@
import ContactsUI import ContactsUI
@objcMembers public class ActionContactModel: ActionModelProtocol {//NSObject, ActionModelProtocol { @objcMembers public class ActionContactModel: ActionModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
@ -37,49 +37,3 @@ import ContactsUI
self.analyticsData = analyticsData 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)
})
}
}
*/