latest contact
This commit is contained in:
parent
f272cd580b
commit
dcc8567401
@ -18,7 +18,7 @@ extern NSString * _Nonnull const KeyActionType;
|
||||
extern NSString * _Nonnull const KeyActionTypeLinkAway;
|
||||
extern NSString * _Nonnull const KeyActionTypeOpen;
|
||||
|
||||
@interface MVMCoreActionHandler : NSObject <CNContactViewControllerDelegate>
|
||||
@interface MVMCoreActionHandler : NSObject <CNContactViewControllerDelegate, CNContactPickerDelegate>
|
||||
|
||||
/// Returns the shared action handler
|
||||
+ (nullable instancetype)sharedActionHandler;
|
||||
|
||||
@ -257,57 +257,45 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Need to ask user for permission to accss their contacts
|
||||
// Privacy - Contacts Usage Description
|
||||
// Access is needed to save your friends information to your Contacts list.
|
||||
- (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
NSString *approach = [actionInformation stringForKey:@"approach"];
|
||||
NSString *MDN = [actionInformation string:KeyCallNumber];
|
||||
|
||||
if ([approach isEqualToString:KeyAdd]) {
|
||||
|
||||
} else if ([approach isEqualToString:KeyCreate]) {
|
||||
|
||||
NSString *firstName = [actionInformation string:@"firstName"];
|
||||
NSString *lastname = [actionInformation string:@"lastName"];
|
||||
|
||||
}
|
||||
|
||||
CNContactStore *store = [[CNContactStore alloc] init];
|
||||
CNMutableContact *mutContact = [[CNMutableContact alloc] init];
|
||||
|
||||
CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelHome value:[[CNPhoneNumber alloc] initWithStringValue:MDN]];
|
||||
NSString *MDN = [actionInformation string:KeyCallNumber];
|
||||
NSString *approach = [actionInformation stringForKey:@"approach"];
|
||||
|
||||
CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]];
|
||||
mutContact.phoneNumbers = @[phone];
|
||||
|
||||
CNContactViewController *controller = [[CNContactViewController alloc] init];
|
||||
controller.contactStore = store;
|
||||
controller.delegate = weakSelf;
|
||||
|
||||
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES];
|
||||
}];
|
||||
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:^{
|
||||
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];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(CNContact *)contact {
|
||||
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController];
|
||||
}
|
||||
|
||||
- (BOOL)contactViewController:(CNContactViewController *)viewController shouldPerformDefaultActionForContactProperty:(CNContactProperty *)property {
|
||||
return YES;
|
||||
}
|
||||
/*
|
||||
let store = CNContactStore()
|
||||
let contact = CNMutableContact()
|
||||
let homePhone = CNLabeledValue(label: CNLabelHome, value: CNPhoneNumber(stringValue :phNo ))
|
||||
contact.phoneNumbers = [homePhone]
|
||||
let controller = CNContactViewController(forUnknownContact : contact)
|
||||
controller.contactStore = store
|
||||
controller.delegate = self
|
||||
self.navigationController?.setNavigationBarHidden(false, animated: true)
|
||||
self.navigationController!.pushViewController(controller, animated: true)
|
||||
*/
|
||||
|
||||
- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Call
|
||||
NSString *callNumber = [actionInformation stringForKey:KeyCallNumber];
|
||||
@ -385,6 +373,43 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - CNContactViewControllerDelegate
|
||||
|
||||
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(CNContact *)contact {
|
||||
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController];
|
||||
}
|
||||
|
||||
- (BOOL)contactViewController:(CNContactViewController *)viewController shouldPerformDefaultActionForContactProperty:(CNContactProperty *)property {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - CNContactPickerDelegate
|
||||
|
||||
- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController];
|
||||
}
|
||||
|
||||
- (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:CNLabelPhoneNumberMobile value:number];
|
||||
NSMutableArray<CNLabeledValue *> *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] presentViewController:controller animated:YES];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - open url functions
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
// Copyright © 2021 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import ContactsUI
|
||||
|
||||
@objcMembers public class ActionContactModel: ActionModelProtocol {
|
||||
|
||||
@objcMembers public class ActionContactModel: ActionModelProtocol {//NSObject, ActionModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -26,11 +28,58 @@
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(callNumber: String, firstName: String? = nil, lastName: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
|
||||
public init(callNumber: String, firstName: String? = nil, lastName: String? = nil, approach: String = KeyCreate, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
|
||||
self.callNumber = callNumber
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.approach = approach
|
||||
self.extraParameters = extraParameters
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user