From f272cd580b1999cb9a1d15be5aa6ad33325811b0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 6 Apr 2021 15:21:09 -0400 Subject: [PATCH] rename and update --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 ++-- .../ActionHandling/MVMCoreActionHandler.h | 3 +- .../ActionHandling/MVMCoreActionHandler.m | 45 ++++++++++++++++--- ...ctModel.swift => ActionContactModel.swift} | 17 ++++--- MVMCore/MVMCore/Models/ModelMapping.swift | 2 +- 5 files changed, 57 insertions(+), 18 deletions(-) rename MVMCore/MVMCore/Models/ActionType/{ActionMakeContactModel.swift => ActionContactModel.swift} (63%) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index cc098b9..97a9bb3 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -34,7 +34,7 @@ 01F2A04C23A82B1B00D954D8 /* ActionCallModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A04B23A82B1B00D954D8 /* ActionCallModel.swift */; }; 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F2A05123A8325100D954D8 /* ModelMapping.swift */; }; 0A42538F23F3414800554656 /* Codable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A42538E23F3414800554656 /* Codable+Helpers.swift */; }; - 0ACC81A22613C73800A9C886 /* ActionMakeContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ACC81A12613C73800A9C886 /* ActionMakeContactModel.swift */; }; + 0ACC81A22613C73800A9C886 /* ActionContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ACC81A12613C73800A9C886 /* ActionContactModel.swift */; }; 0AEBB84625FA75C000EA80EE /* ActionOpenSMSModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */; }; 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */; }; 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -170,7 +170,7 @@ 0A11030B20864F94008ADD90 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = ""; }; 0A11030C20864F9A008ADD90 /* es-MX */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-MX"; path = "es-MX.lproj/Localizable.strings"; sourceTree = ""; }; 0A42538E23F3414800554656 /* Codable+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Codable+Helpers.swift"; sourceTree = ""; }; - 0ACC81A12613C73800A9C886 /* ActionMakeContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionMakeContactModel.swift; sourceTree = ""; }; + 0ACC81A12613C73800A9C886 /* ActionContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionContactModel.swift; sourceTree = ""; }; 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenSMSModel.swift; sourceTree = ""; }; 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionShareModel.swift; sourceTree = ""; }; 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreSessionTimeHandler.h; sourceTree = ""; }; @@ -454,7 +454,7 @@ BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */, D27073B625BB45C4001C7246 /* ActionActionsModel.swift */, 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */, - 0ACC81A12613C73800A9C886 /* ActionMakeContactModel.swift */, + 0ACC81A12613C73800A9C886 /* ActionContactModel.swift */, ); path = ActionType; sourceTree = ""; @@ -856,7 +856,7 @@ 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, D27073B725BB45C4001C7246 /* ActionActionsModel.swift in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, - 0ACC81A22613C73800A9C886 /* ActionMakeContactModel.swift in Sources */, + 0ACC81A22613C73800A9C886 /* ActionContactModel.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 1dc2aa5..0d15a0b 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -11,13 +11,14 @@ #import #import #import +#import @class DelegateObject; extern NSString * _Nonnull const KeyActionType; extern NSString * _Nonnull const KeyActionTypeLinkAway; extern NSString * _Nonnull const KeyActionTypeOpen; -@interface MVMCoreActionHandler : NSObject +@interface MVMCoreActionHandler : NSObject /// Returns the shared action handler + (nullable instancetype)sharedActionHandler; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 09a15f2..3915d14 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -27,6 +27,7 @@ #import #import #import "MVMCoreLoadingOverlayHandler.h" +#import NSString * const KeyActionType = @"actionType"; NSString * const KeyActionTypeLinkAway = @"openURL"; @@ -258,21 +259,55 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (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"]; + } -// NSString *message = [actionInformation stringForKey:KeyMessage]; -// NSString *smsQuery = [NSString stringWithFormat:@"sms:%@&body=%@", phoneNumber, message]; - // NSURL *url = [NSURL URLWithString:[smsQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; - // [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; -// [MVMCoreActionUtility linkAway:[smsQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] appURLString:nil]; + CNContactStore *store = [[CNContactStore alloc] init]; + CNMutableContact *mutContact = [[CNMutableContact alloc] init]; + + CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelHome 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]; + }]; } +- (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]; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift similarity index 63% rename from MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift rename to MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift index 1c9bbd4..19aa3c1 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift @@ -1,5 +1,5 @@ // -// ActionMakeContactModel.swift +// ActionContactModel.swift // MVMCore // // Created by Kevin Christiano on 3/30/21. @@ -7,7 +7,7 @@ // -@objcMembers public class ActionMakeContactModel: ActionModelProtocol { +@objcMembers public class ActionContactModel: ActionModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -15,18 +15,21 @@ public static var identifier: String = "contact" public var actionType: String = ActionCallModel.identifier // TODO: decode into phone number once action handler is re-written -// public var callNumber: String + public var callNumber: String + public var firstName: String? + public var lastName: String? public var approach: String = KeyCreate public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? - + //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(callNumber: String, message: String?, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { -// self.callNumber = callNumber -// self.message = message + public init(callNumber: String, firstName: String? = nil, lastName: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + self.callNumber = callNumber + self.firstName = firstName + self.lastName = lastName self.extraParameters = extraParameters self.analyticsData = analyticsData } diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 660a534..26cb696 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -23,7 +23,7 @@ try? ModelRegistry.register(ActionNoopModel.self) try? ModelRegistry.register(ActionActionsModel.self) try? ModelRegistry.register(ActionOpenSMSModel.self) - try? ModelRegistry.register(ActionMakeContactModel.self) + try? ModelRegistry.register(ActionContactModel.self) } }