From c8f804abdb2289a9fd22555ce8eb4cad80e65029 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 11 Mar 2021 11:57:18 -0500 Subject: [PATCH 01/18] sms action --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../ActionHandling/MVMCoreActionHandler.h | 3 ++ .../ActionHandling/MVMCoreActionHandler.m | 14 ++++++++ .../MVMCore/Constants/MVMCoreJSONConstants.h | 1 + .../MVMCore/Constants/MVMCoreJSONConstants.m | 1 + .../ActionType/ActionOpenSMSModel.swift | 33 +++++++++++++++++++ MVMCore/MVMCore/Models/ModelMapping.swift | 2 +- 7 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionOpenSMSModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 449ae7c..fe05d49 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -34,6 +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 */; }; + 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, ); }; }; 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */; }; @@ -167,6 +168,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 = ""; }; + 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 = ""; }; 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreSessionTimeHandler.m; sourceTree = ""; }; @@ -446,6 +448,7 @@ 94C014D824212360005811A9 /* ActionSettingModel.swift */, BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */, D27073B625BB45C4001C7246 /* ActionActionsModel.swift */, + 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */, ); path = ActionType; sourceTree = ""; @@ -885,6 +888,7 @@ 016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */, D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, + 0AEBB84625FA75C000EA80EE /* ActionOpenSMSModel.swift in Sources */, 016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */, 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */, D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 2f41e93..14930a2 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -50,6 +50,9 @@ extern NSString * _Nonnull const KeyActionTypeOpen; /// Goes back - (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; +/// Opens Text Message +- (void)smsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; + /// Makes a phone call - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index ddb1fab..295d393 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -69,6 +69,9 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeCall]) { [self callAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypeSMS]) { + [self smsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } else if ([actionType isEqualToString:KeyActionTypeShare]) { [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -261,6 +264,17 @@ NSString * const KeyActionTypeOpen = @"openPage"; } } +/// Send Text Message +- (void)smsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { + + NSString *phoneNumber = [actionInformation stringForKey:KeyCallNumber]; + 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]; +} + - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { // Call NSString *callNumber = [actionInformation stringForKey:KeyCallNumber]; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index c2d7f8e..907feed 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -34,6 +34,7 @@ extern NSString * const KeyActionTypeBack; extern NSString * const KeyActionTypeShare; extern NSString * const KeyShareType; extern NSString * const KeyShareText; +extern NSString * const KeyActionTypeSMS; extern NSString * const KeyActionTypeCall; extern NSString * const KeyActionTypePreviousSubmit; extern NSString * const KeyActionTypeCancel; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 80317ea..a678877 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -35,6 +35,7 @@ NSString * const KeyActionTypeRestart = @"restart"; NSString * const KeyActionTypeBack = @"back"; NSString * const KeyActionTypeShare = @"share"; NSString * const KeyActionTypeCall = @"call"; +NSString * const KeyActionTypeSMS = @"sms"; NSString * const KeyActionTypePreviousSubmit = @"previousSubmit"; NSString * const KeyActionTypeCancel = @"cancel"; NSString * const KeyActionTypeRedirect = @"switchApp"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenSMSModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenSMSModel.swift new file mode 100644 index 0000000..33fed5e --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenSMSModel.swift @@ -0,0 +1,33 @@ +// +// ActionOpenSMSModel.swift +// MVMCore +// +// Created by Kevin Christiano on 3/11/21. +// Copyright © 2021 myverizon. All rights reserved. +// + + +@objcMembers public class ActionOpenSMSModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "sms" + public var actionType: String = ActionCallModel.identifier + // TODO: decode into phone number once action handler is re-written + public var callNumber: String + public var message: String? + 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 + self.extraParameters = extraParameters + self.analyticsData = analyticsData + } +} diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 6c3df04..f13e3e8 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -6,7 +6,6 @@ // Copyright © 2019 myverizon. All rights reserved. // -import Foundation @objcMembers public class ModelMapping: NSObject { @@ -22,5 +21,6 @@ import Foundation try? ModelRegistry.register(ActionSettingModel.self) try? ModelRegistry.register(ActionNoopModel.self) try? ModelRegistry.register(ActionActionsModel.self) + try? ModelRegistry.register(ActionOpenSMSModel.self) } } From 69f908173c65c48dd83f0e72b3a9ed3ad420b053 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 23 Mar 2021 12:09:53 -0400 Subject: [PATCH 02/18] merging --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From dc421e7498d33aae33dceaa74ec204342280c839 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 30 Mar 2021 16:53:51 -0400 Subject: [PATCH 03/18] adding class contact --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 +++ .../ActionType/ActionMakeContactModel.swift | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 176463b..5fccb56 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -35,6 +35,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 */; }; 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, ); }; }; @@ -171,6 +172,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 = ""; }; 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 = ""; }; @@ -455,6 +457,7 @@ BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */, D27073B625BB45C4001C7246 /* ActionActionsModel.swift */, 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */, + 0ACC81A12613C73800A9C886 /* ActionMakeContactModel.swift */, ); path = ActionType; sourceTree = ""; @@ -856,6 +859,7 @@ 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, D27073B725BB45C4001C7246 /* ActionActionsModel.swift in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, + 0ACC81A22613C73800A9C886 /* ActionMakeContactModel.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, AFBB96691FBA3A570008D868 /* MVMCoreRequestParameters.m in Sources */, diff --git a/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift new file mode 100644 index 0000000..d2f10d4 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift @@ -0,0 +1,33 @@ +// +// ActionMakeContactModel.swift +// MVMCore +// +// Created by Kevin Christiano on 3/30/21. +// Copyright © 2021 myverizon. All rights reserved. +// + + +@objcMembers public class ActionMakeContactModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + 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 message: String? + 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 + self.extraParameters = extraParameters + self.analyticsData = analyticsData + } +} From f595e40f2ff5114c0de17f5078350e438ce39e4e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 30 Mar 2021 16:56:10 -0400 Subject: [PATCH 04/18] contact action. --- MVMCore/MVMCore/Models/ModelMapping.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index f13e3e8..b1bdd71 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -22,5 +22,7 @@ try? ModelRegistry.register(ActionNoopModel.self) try? ModelRegistry.register(ActionActionsModel.self) try? ModelRegistry.register(ActionOpenSMSModel.self) + try? ModelRegistry.register(ActionMakeContactModel.self) } } + From d4dfe2567b4a04a33622a0d927ba3fc4ae5423c7 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 31 Mar 2021 10:53:37 -0400 Subject: [PATCH 05/18] latest updates for fios additions. --- .../ActionHandling/MVMCoreActionHandler.m | 82 ++++++++++++------- .../MVMCore/Constants/MVMCoreJSONConstants.h | 4 + .../MVMCore/Constants/MVMCoreJSONConstants.m | 4 + .../ActionType/ActionMakeContactModel.swift | 8 +- .../MVMCore/Models/Model/ModelProtocol.swift | 5 +- 5 files changed, 65 insertions(+), 38 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 243ca70..9696494 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -71,10 +71,13 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeSMS]) { [self smsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeContact]) { + [self contactAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; } else if ([actionType isEqualToString:KeyActionTypeShare]) { [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - + } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { [self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -86,7 +89,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeSettings]) { [self settingsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - + } else if ([actionType isEqualToString:KeyActionTypeNoop]) { } else if ([actionType isEqualToString:KeyActionTypeActions]) { [self actions:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -102,7 +105,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; completionHandler(nil); return; } - + if (showLoadingOverlay) { [[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading]; } @@ -115,22 +118,22 @@ NSString * const KeyActionTypeOpen = @"openPage"; NSError *error = nil; [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Fetching client parameters"]; - + ClientParameterHandler *clientParameterHandler = [[ClientParameterHandler alloc] init]; [clientParameterHandler getParametersWith:clientParametersMap - requestParameters:requestParameters - error:&error - completionHandler:^(NSDictionary * _Nullable clientParameters) { - [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Finshed fetching client parameters"]; - if (clientParameters) { - stopLoadingOverlay(); - completionHandler(clientParameters); - } else { - [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client parameters"]; - stopLoadingOverlay(); - completionHandler(nil); - } - }]; + requestParameters:requestParameters + error:&error + completionHandler:^(NSDictionary * _Nullable clientParameters) { + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Finshed fetching client parameters"]; + if (clientParameters) { + stopLoadingOverlay(); + completionHandler(clientParameters); + } else { + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client parameters"]; + stopLoadingOverlay(); + completionHandler(nil); + } + }]; if (error) { stopLoadingOverlay(); @@ -158,14 +161,14 @@ NSString * const KeyActionTypeOpen = @"openPage"; // Loads the given page type. NSString *pageType = [actionInformation stringForKey:KeyPageType]; - + if (pageType.length == 0) { // No page type to load, show error. MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]]; [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; return; } - + MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation]; [self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { if ([delegateObject.actionDelegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { @@ -262,11 +265,28 @@ NSString * const KeyActionTypeOpen = @"openPage"; NSString *phoneNumber = [actionInformation stringForKey:KeyCallNumber]; 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]; + // NSURL *url = [NSURL URLWithString:[smsQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + // [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; [MVMCoreActionUtility linkAway:[smsQuery stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] appURLString:nil]; } +- (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { + + NSString *approach = [actionInformation stringForKey:@"approach"]; + + if ([approach isEqualToString:KeyAdd]) { + + } else if ([approach isEqualToString:KeyCreate]) { + + } + +// 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]; +} + - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { // Call NSString *callNumber = [actionInformation stringForKey:KeyCallNumber]; @@ -347,33 +367,33 @@ NSString * const KeyActionTypeOpen = @"openPage"; #pragma mark - open url functions - (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - + __weak typeof(self) weakSelf = self; void (^performAction)(NSDictionary*) = ^(NSDictionary* extraParamters) { - + NSMutableDictionary *actionWithClientParameters = [actionInformation mutableCopy]; NSMutableDictionary *extraParametersT = [extraParamters mutableCopy]; [extraParametersT addEntriesFromDictionary:[actionWithClientParameters dictionaryForKey:KeyExtraParameters]]; actionWithClientParameters[KeyExtraParameters] = extraParametersT; - + // Gets the app url NSURL *appURL = nil; NSString *appURLString = [actionWithClientParameters string:KeyLinkAwayAppURL]; if (appURLString.length > 0) { appURL = [NSURL URLWithString:appURLString]; } - + // Gets the browser url NSURL *otherURL = nil; NSString *otherURLString = [actionWithClientParameters string:KeyLinkAwayURL]; if (otherURLString.length > 0) { otherURL = [NSURL URLWithString:otherURLString]; } - + // Provide the URL and App URL to be modified if needed by a subclass or delegate. [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionWithClientParameters additionalData:additionalData delegateObject:delegateObject]; }; - + [self getClientParameter:[actionInformation dict:KeyClientParameters] requestParameters:nil showLoadingOverlay:true @@ -437,13 +457,13 @@ NSString * const KeyActionTypeOpen = @"openPage"; } + (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - + NSDictionary *clientParamters = [actionInformation dict:KeyClientParameters]; if (clientParamters) { [[MVMCoreActionHandler sharedActionHandler] getClientParameter:clientParamters - requestParameters: requestParameters.parameters - showLoadingOverlay: !requestParameters.backgroundRequest - completionHandler: ^(NSDictionary * _Nullable jsonDictionary) { + requestParameters: requestParameters.parameters + showLoadingOverlay: !requestParameters.backgroundRequest + completionHandler: ^(NSDictionary * _Nullable jsonDictionary) { [requestParameters addRequestParameters:jsonDictionary]; [[MVMCoreLoadHandler sharedGlobal] loadRequest:requestParameters dataForPage:additionalData delegateObject:delegateObject]; }]; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 907feed..f9746bc 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -26,6 +26,9 @@ extern NSString * const KeyButtonMap; extern NSString * const KeyOpenSupport; extern NSString * const KeyPostAction; +extern NSString * const KeyAdd; +extern NSString * const KeyCreate; + extern NSString * const KeyLinks; extern NSString * const KeyTitle; extern NSString * const KeyMessage; @@ -35,6 +38,7 @@ extern NSString * const KeyActionTypeShare; extern NSString * const KeyShareType; extern NSString * const KeyShareText; extern NSString * const KeyActionTypeSMS; +extern NSString * const KeyActionTypeContact; extern NSString * const KeyActionTypeCall; extern NSString * const KeyActionTypePreviousSubmit; extern NSString * const KeyActionTypeCancel; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index a678877..8f572f7 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -28,6 +28,9 @@ NSString * const KeyButtonMap = @"ButtonMap"; NSString * const KeyOpenSupport = @"openSupport"; NSString * const KeyPostAction = @"PostAction"; +NSString * const KeyAdd = @"add"; +NSString * const KeyCreate = @"create"; + NSString * const KeyLinks = @"Links"; NSString * const KeyTitle = @"title"; NSString * const KeyMessage = @"message"; @@ -36,6 +39,7 @@ NSString * const KeyActionTypeBack = @"back"; NSString * const KeyActionTypeShare = @"share"; NSString * const KeyActionTypeCall = @"call"; NSString * const KeyActionTypeSMS = @"sms"; +NSString * const KeyActionTypeContact = @"contact"; NSString * const KeyActionTypePreviousSubmit = @"previousSubmit"; NSString * const KeyActionTypeCancel = @"cancel"; NSString * const KeyActionTypeRedirect = @"switchApp"; diff --git a/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift index d2f10d4..1c9bbd4 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionMakeContactModel.swift @@ -15,8 +15,8 @@ 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 message: String? +// public var callNumber: String + public var approach: String = KeyCreate public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -25,8 +25,8 @@ //-------------------------------------------------- public init(callNumber: String, message: String?, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { - self.callNumber = callNumber - self.message = message +// self.callNumber = callNumber +// self.message = message self.extraParameters = extraParameters self.analyticsData = analyticsData } diff --git a/MVMCore/MVMCore/Models/Model/ModelProtocol.swift b/MVMCore/MVMCore/Models/Model/ModelProtocol.swift index a7adfcb..960f593 100644 --- a/MVMCore/MVMCore/Models/Model/ModelProtocol.swift +++ b/MVMCore/MVMCore/Models/Model/ModelProtocol.swift @@ -35,11 +35,11 @@ public protocol ModelProtocol: Codable { extension ModelProtocol { static public func decode(keyedContainer: KeyedDecodingContainer, codingKey: K) throws -> Self? { - return try keyedContainer.decodeIfPresent(self, forKey: codingKey) + try keyedContainer.decodeIfPresent(self, forKey: codingKey) } static public func decode(unkeyedContainer: inout UnkeyedDecodingContainer) throws -> Self? { - return try unkeyedContainer.decodeIfPresent(self) + try unkeyedContainer.decodeIfPresent(self) } public func encode(keyedContainer: inout KeyedEncodingContainer, codingKey: K) throws { @@ -50,4 +50,3 @@ extension ModelProtocol { try unkeyedContainer.encode(self) } } - From d9aa011f051075be4e98b7fe066dc4babde74082 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 6 Apr 2021 14:43:50 -0400 Subject: [PATCH 06/18] undo --- .../MVMCore/ActionHandling/MVMCoreActionHandler.m | 14 -------------- MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m | 1 - 2 files changed, 15 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 9696494..09a15f2 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -69,9 +69,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeCall]) { [self callAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - } else if ([actionType isEqualToString:KeyActionTypeSMS]) { - [self smsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - } else if ([actionType isEqualToString:KeyActionTypeContact]) { [self contactAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; @@ -259,17 +256,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; } } -/// Send Text Message -- (void)smsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - - NSString *phoneNumber = [actionInformation stringForKey:KeyCallNumber]; - 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]; -} - - (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { NSString *approach = [actionInformation stringForKey:@"approach"]; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 8f572f7..edad8da 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -38,7 +38,6 @@ NSString * const KeyActionTypeRestart = @"restart"; NSString * const KeyActionTypeBack = @"back"; NSString * const KeyActionTypeShare = @"share"; NSString * const KeyActionTypeCall = @"call"; -NSString * const KeyActionTypeSMS = @"sms"; NSString * const KeyActionTypeContact = @"contact"; NSString * const KeyActionTypePreviousSubmit = @"previousSubmit"; NSString * const KeyActionTypeCancel = @"cancel"; From f272cd580b1999cb9a1d15be5aa6ad33325811b0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 6 Apr 2021 15:21:09 -0400 Subject: [PATCH 07/18] 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) } } From dcc8567401ded41f04f0100d119201cf64dae9ff Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 10:22:30 -0400 Subject: [PATCH 08/18] latest contact --- .../ActionHandling/MVMCoreActionHandler.h | 2 +- .../ActionHandling/MVMCoreActionHandler.m | 109 +++++++++++------- .../ActionType/ActionContactModel.swift | 53 ++++++++- 3 files changed, 119 insertions(+), 45 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 0d15a0b..ff9471d 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -18,7 +18,7 @@ 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 3915d14..1165aec 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -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 *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 { diff --git a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift index 19aa3c1..e5f1b38 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift @@ -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) + }) + } +} +*/ From f5613644a0079400eb3610e12e9b2b689884e7de Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 11:41:49 -0400 Subject: [PATCH 09/18] 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) - }) - } -} -*/ From 4686dc82568729d1bb14b9395e35b6de38493b30 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 14:15:12 -0400 Subject: [PATCH 10/18] contact behavior --- .../ActionHandling/MVMCoreActionHandler.m | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index a09eb6a..39d43ca 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -274,9 +274,10 @@ NSString * const KeyActionTypeOpen = @"openPage"; contact.phoneNumbers = @[phone]; if ([approach isEqualToString:KeyAdd]) { - // Nothing for now. [MVMCoreDispatchUtility performBlockOnMainThread:^{ CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + // Setting to accessibilityValue as a workaround to pass data via the delegate function. + [controller setAccessibilityValue:MDN]; controller.delegate = weakSelf; [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; @@ -395,22 +396,27 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (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:CNLabelOther value:number]; - NSMutableArray *phoneNumbers = [NSMutableArray new]; - [phoneNumbers addObject:labelValue]; - [phoneNumbers addObjectsFromArray:existingContact.phoneNumbers]; - existingContact.phoneNumbers = phoneNumbers; + // This is a means to pass the data to this delegate function. + NSString *MDN = picker.accessibilityValue; - CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact]; - controller.contactStore = store; - controller.delegate = self; - - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; - }]; + if (MDN) { + CNContactStore *store = [[CNContactStore alloc] init]; + CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; + CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:MDN]; + 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]; + controller.contactStore = store; + controller.delegate = self; + + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; + }]; + } } #pragma mark - Open URL From c3601741c8cda29f4b3b1a6550eb17b74a1a41d5 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 14:24:30 -0400 Subject: [PATCH 11/18] undo --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From dc90af50b2a4f3e1d62fbcdb1555ee983c32663c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 15:37:40 -0400 Subject: [PATCH 12/18] for reference. --- .../ActionHandling/MVMCoreActionHandler.m | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 39d43ca..7248264 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -257,48 +257,50 @@ 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 *MDN = [actionInformation string:KeyCallNumber]; - - if (MDN) { - CNMutableContact *contact = [[CNMutableContact alloc] init]; - NSString *approach = [actionInformation stringForKey:@"approach"]; +// CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; +// +// if (status == CNAuthorizationStatusAuthorized) { + __weak typeof(self) weakSelf = self; - CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; - contact.phoneNumbers = @[phone]; + NSString *MDN = [actionInformation string:KeyCallNumber]; - if ([approach isEqualToString:KeyAdd]) { - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; - // Setting to accessibilityValue as a workaround to pass data via the delegate function. - [controller setAccessibilityValue:MDN]; - 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]; - }]; + if (MDN) { + CNMutableContact *contact = [[CNMutableContact alloc] init]; + NSString *approach = [actionInformation stringForKey:@"approach"]; + + CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; + contact.phoneNumbers = @[phone]; + + if ([approach isEqualToString:KeyAdd]) { + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + // Setting to accessibilityValue as a workaround to pass data via the delegate function. + [controller setAccessibilityValue:MDN]; + 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]; + }]; + } } - } +// } } - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { From a25e88427a9bb1b8fc2318f2771ae95d1b51a99c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 7 Apr 2021 16:11:18 -0400 Subject: [PATCH 13/18] contact action --- .../ActionHandling/MVMCoreActionHandler.m | 73 +++++++++---------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 7248264..7c15527 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -257,50 +257,45 @@ NSString * const KeyActionTypeOpen = @"openPage"; } } -// Privacy - Contacts Usage Description - (void)contactAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { -// CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; -// -// if (status == CNAuthorizationStatusAuthorized) { - __weak typeof(self) weakSelf = self; + __weak typeof(self) weakSelf = self; + + NSString *MDN = [actionInformation string:KeyCallNumber]; + + if (MDN) { + CNMutableContact *contact = [[CNMutableContact alloc] init]; + NSString *approach = [actionInformation stringForKey:@"approach"]; - NSString *MDN = [actionInformation string:KeyCallNumber]; + CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; + contact.phoneNumbers = @[phone]; - if (MDN) { - CNMutableContact *contact = [[CNMutableContact alloc] init]; - NSString *approach = [actionInformation stringForKey:@"approach"]; - - CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; - contact.phoneNumbers = @[phone]; - - if ([approach isEqualToString:KeyAdd]) { - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; - // Setting to accessibilityValue as a workaround to pass data via the delegate function. - [controller setAccessibilityValue:MDN]; - 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]; - }]; - } + if ([approach isEqualToString:KeyAdd]) { + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + // Setting to accessibilityValue as a workaround to pass data via the delegate function. + [controller setAccessibilityValue:MDN]; + 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]; + }]; } -// } + } } - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { From 440068246904fdd25ba5948209e5567f62f58a5e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 9 Apr 2021 14:28:05 -0400 Subject: [PATCH 14/18] space --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index e275baf..c490be2 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -72,7 +72,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeSMS]) { [self smsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - + } else if ([actionType isEqualToString:KeyActionTypeContact]) { [self contactAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; From 1d968bd2c17ade1e10bce683ecc7499793d300ff Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 9 Apr 2021 16:43:37 -0400 Subject: [PATCH 15/18] merging. molecule updates. --- .../ActionHandling/MVMCoreActionHandler.m | 102 +++++++++--------- .../ActionType/ActionContactModel.swift | 6 +- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index c490be2..7fc063a 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -272,40 +272,39 @@ NSString * const KeyActionTypeOpen = @"openPage"; __weak typeof(self) weakSelf = self; - NSString *MDN = [actionInformation string:KeyCallNumber]; + NSString *phoneNumber = [actionInformation string:@"phoneNumber"]; - if (MDN) { - CNMutableContact *contact = [[CNMutableContact alloc] init]; - NSString *approach = [actionInformation stringForKey:@"approach"]; - - CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:MDN]]; - contact.phoneNumbers = @[phone]; - - if ([approach isEqualToString:KeyAdd]) { - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; - // Setting to accessibilityValue as a workaround to pass data via the delegate function. - [controller setAccessibilityValue:MDN]; - 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]; - }]; - } + if (!phoneNumber) { return; } + CNMutableContact *contact = [[CNMutableContact alloc] init]; + NSString *approach = [actionInformation stringForKey:@"approach"]; + + CNLabeledValue *phone = [[CNLabeledValue alloc] initWithLabel:CNLabelOther value:[[CNPhoneNumber alloc] initWithStringValue:phoneNumber]]; + contact.phoneNumbers = @[phone]; + + if ([approach isEqualToString:KeyAdd]) { + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; + // Setting to accessibilityValue as a workaround to pass data via the delegate function. + [controller setAccessibilityValue:phoneNumber]; + 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]; + }]; } } @@ -405,26 +404,25 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact { // This is a means to pass the data to this delegate function. - NSString *MDN = picker.accessibilityValue; + NSString *phoneNumber = picker.accessibilityValue; - if (MDN) { - CNContactStore *store = [[CNContactStore alloc] init]; - CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; - CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:MDN]; - 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]; - controller.contactStore = store; - controller.delegate = self; - - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; - }]; - } + if (!phoneNumber) { return; } + CNContactStore *store = [[CNContactStore alloc] init]; + CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; + CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:phoneNumber]; + 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]; + controller.contactStore = store; + controller.delegate = self; + + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; + }]; } #pragma mark - Open URL diff --git a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift index 1fee221..facfbef 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift @@ -17,7 +17,7 @@ import ContactsUI 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 phoneNumber: String public var firstName: String? public var lastName: String? public var approach: String = KeyCreate @@ -28,8 +28,8 @@ import ContactsUI // MARK: - Initializer //-------------------------------------------------- - public init(callNumber: String, firstName: String? = nil, lastName: String? = nil, approach: String = KeyCreate, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { - self.callNumber = callNumber + public init(phoneNumber: String, firstName: String? = nil, lastName: String? = nil, approach: String = KeyCreate, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + self.phoneNumber = phoneNumber self.firstName = firstName self.lastName = lastName self.approach = approach From 98ddd3331d7dd25b69b494968f77e81228787099 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 9 Apr 2021 16:53:35 -0400 Subject: [PATCH 16/18] Added new behavior. Moved protocols to folder. --- MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift index facfbef..6ccbc13 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionContactModel.swift @@ -16,7 +16,7 @@ import ContactsUI 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 phoneNumber: String public var firstName: String? public var lastName: String? From 4ba0e3adfb9b66784e07b9406bdd1b6de9c0def3 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 12 Apr 2021 11:04:45 -0400 Subject: [PATCH 17/18] comment. removing header import. --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index ff9471d..1dc2aa5 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -11,14 +11,13 @@ #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; From e54a41481498e0f2d8319f93826221f9f4c0c945 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 12 Apr 2021 13:44:27 -0400 Subject: [PATCH 18/18] moved protocol. --- .../ActionHandling/MVMCoreActionHandler.m | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 7fc063a..15fab4e 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -33,8 +33,10 @@ NSString * const KeyActionType = @"actionType"; NSString * const KeyActionTypeLinkAway = @"openURL"; NSString * const KeyActionTypeOpen = @"openPage"; -@implementation MVMCoreActionHandler +@interface MVMCoreActionHandler() +@end +@implementation MVMCoreActionHandler + (nullable instancetype)sharedActionHandler { return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].actionHandler classToVerify:self]; } @@ -285,7 +287,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [MVMCoreDispatchUtility performBlockOnMainThread:^{ CNContactPickerViewController *controller = [[CNContactPickerViewController alloc] init]; // Setting to accessibilityValue as a workaround to pass data via the delegate function. - [controller setAccessibilityValue:phoneNumber]; + [controller.view setAccessibilityIdentifier:phoneNumber]; controller.delegate = weakSelf; [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:controller animated:YES]; @@ -404,23 +406,25 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact { // This is a means to pass the data to this delegate function. - NSString *phoneNumber = picker.accessibilityValue; + NSString *phoneNumber = picker.view.accessibilityIdentifier; if (!phoneNumber) { return; } CNContactStore *store = [[CNContactStore alloc] init]; - CNMutableContact *existingContact = [(CNMutableContact*)contact mutableCopy]; - CNPhoneNumber * number = [[CNPhoneNumber alloc] initWithStringValue:phoneNumber]; - CNLabeledValue * labelValue = [[CNLabeledValue alloc]initWithLabel:CNLabelOther value:number]; + CNMutableContact *existingContact = [(CNMutableContact *)contact mutableCopy]; + CNPhoneNumber *number = [[CNPhoneNumber alloc] initWithStringValue:phoneNumber]; + 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]; - controller.contactStore = store; - controller.delegate = self; + __weak typeof(self) weakSelf = self; [MVMCoreDispatchUtility performBlockOnMainThread:^{ + CNContactViewController *controller = [CNContactViewController viewControllerForNewContact:existingContact]; + controller.contactStore = store; + controller.delegate = weakSelf; + [[MVMCoreNavigationHandler sharedNavigationHandler] pushViewController:controller animated:YES]; }]; }