From 068714a0018a798256079d3e827402c0f37a0a19 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 29 Aug 2022 20:08:21 -0400 Subject: [PATCH 01/68] create core events for actions and clientparameters tracking --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 8 ++ .../ActionHandling/MVMCoreActionHandler.swift | 37 +++-- .../MVMCore/Categories/Date+Extension.swift | 16 +++ .../MVMCore/OtherHandlers/MVMCoreEvent.swift | 126 ++++++++++++++++++ .../OtherHandlers/MVMCoreLoggingHandler.h | 1 + .../OtherHandlers/MVMCoreLoggingHandler.m | 2 + 6 files changed, 179 insertions(+), 11 deletions(-) create mode 100644 MVMCore/MVMCore/Categories/Date+Extension.swift create mode 100644 MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index bdd9165..8a2b307 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -39,6 +39,8 @@ 0AEBB84625FA75C000EA80EE /* ActionOpenSMSModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */; }; 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */; }; 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */; }; + 2723337B28BD534D004EAEE0 /* MVMCoreEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */; }; + 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337C28BD53C2004EAEE0 /* Date+Extension.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 */; }; 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */; }; @@ -196,6 +198,8 @@ 0AEBB84525FA75C000EA80EE /* ActionOpenSMSModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenSMSModel.swift; sourceTree = ""; }; 0AFF597923FC6E60005C24E8 /* ActionShareModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionShareModel.swift; sourceTree = ""; }; 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionRunJavaScriptModel.swift; sourceTree = ""; }; + 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreEvent.swift; sourceTree = ""; }; + 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.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 = ""; }; 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreErrorObject.m; sourceTree = ""; }; @@ -435,6 +439,7 @@ 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */, 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */, 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */, + 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */, ); path = Categories; sourceTree = ""; @@ -687,6 +692,7 @@ AFEEE81C1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h */, AFEEE81D1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m */, D288D5F426C6EFE000A5C365 /* MVMCoreLoggingHandler+Extension.swift */, + 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */, ); path = OtherHandlers; sourceTree = ""; @@ -912,6 +918,7 @@ AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, + 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */, AF70699A287DD02400077CF6 /* ActionContactHandler.swift in Sources */, AF69D4F3286E9DCE00BC6862 /* ActionActionsHandler.swift in Sources */, 946EE1BC237B691A0036751F /* ActionOpenPageModel.swift in Sources */, @@ -950,6 +957,7 @@ 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */, 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, + 2723337B28BD534D004EAEE0 /* MVMCoreEvent.swift in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, 94C014D924212360005811A9 /* ActionSettingModel.swift in Sources */, D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index 398a590..ee7c1ef 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -84,7 +84,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { /// Handle an action with the given model. open func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { try Task.checkCancellation() - var additionalData = MVMCoreActionHandler.setUUID(additionalData: additionalData) + var (additionalData, uuid) = MVMCoreActionHandler.setUUID(additionalData: additionalData) MVMCoreActionHandler.log(string: "Begin Action: \(model.actionType)", additionalData: additionalData) defer { MVMCoreActionHandler.log(string: "End Action: \(model.actionType)", additionalData: additionalData) @@ -97,17 +97,20 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { do { let handlerType = try ModelRegistry.getHandler(model) as! MVMCoreActionHandlerProtocol.Type let handler = handlerType.init() + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionInvoked(name: model.actionType, pageType: pageType(from: delegateObject), uuid: uuid)) if let handler = handler as? MVMCoreJSONActionHandlerProtocol { // Needed until we can remove legacy delegate functions. try await handler.performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData) } else { try await handler.execute(with: model, delegateObject: delegateObject, additionalData: additionalData) } + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionComplete(name: model.actionType, pageType: pageType(from: delegateObject), uuid: uuid)) } catch ModelRegistry.Error.handlerNotMapped { try Task.checkCancellation() // Allows custom handling if there no handler for the action. guard try await handleUnregisteredAction(with: model, json: json, additionalData: additionalData, delegateObject: delegateObject) else { MVMCoreActionHandler.log(string: "Failed Action Unknown", additionalData: additionalData) + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionNotFound(name: model.actionType , pageType: pageType(from: delegateObject))) throw ActionError.unknownAction(type: model.actionType) } } catch { @@ -132,9 +135,10 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { // MARK: - Legacy Holdovers - static public func setUUID(additionalData: [AnyHashable: Any]?, force: Bool = false) -> [AnyHashable: Any] { - if !force && getUUID(additionalData: additionalData) != nil { return additionalData! } - return additionalData.dictionaryAdding(key: "Action-UUID", value: UUID().uuidString) + static public func setUUID(additionalData: [AnyHashable: Any]?, force: Bool = false) -> ([AnyHashable: Any], String) { + if !force, let uuid = getUUID(additionalData: additionalData) { return (additionalData!, uuid) } + let newUUID = UUID().uuidString + return (additionalData.dictionaryAdding(key: "Action-UUID", value: newUUID), newUUID) } static public func getUUID(additionalData: [AnyHashable: Any]?) -> String? { @@ -145,6 +149,17 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ActionHandler: UUID: \(String(describing: getUUID(additionalData: additionalData))), \(string)") } + fileprivate func logActionError(_ error: Error, _ actionType: String?, _ additionalData: [AnyHashable: Any]?, _ delegateObject: DelegateObject?) { + MVMCoreActionHandler.log(string: "Failed Action: Error \(error)", additionalData: additionalData) + if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: actionType ?? "noAction")) { + defaultHandleActionError(errorObject, additionalData: additionalData) + } + } + + fileprivate func pageType(from delegateObject: DelegateObject?) -> String { + return (delegateObject?.loadDelegate as? MVMCoreViewControllerProtocol)?.pageType ?? "unknown" + } + /// Legacy handle action with json. @objc(handleActionWithDictionary:additionalData:delegateObject:) open func handleAction(with json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { @@ -159,16 +174,16 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { } catch { let actionType = json?.optionalStringForKey(KeyActionType) switch error { + case ModelRegistry.Error.decoderError, is DecodingError: + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionFailedToDecode(pageType: pageType(from: delegateObject), error: error)) case ModelRegistry.Error.decoderErrorModelNotMapped: // If the model is not mapped, give the legacy classes a chance to handle it. if try await handleUnregisteredAction(with: nil, json: json!, additionalData: additionalData, delegateObject: delegateObject) == false { - fallthrough + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionNotFound(name: actionType ?? "noAction", pageType: pageType(from: delegateObject))) + logActionError(error, actionType, additionalData, delegateObject) } default: - MVMCoreActionHandler.log(string: "Failed Action: Error \(error)", additionalData: additionalData) - if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: actionType ?? "noAction")) { - defaultHandleActionError(errorObject, additionalData: additionalData) - } + logActionError(error, actionType, additionalData, delegateObject) } } } @@ -177,8 +192,8 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { /// Bridges the legacy json using functions and the new model using functions. open func handleAction(with model: ActionModelProtocol, json: [AnyHashable: Any], additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { try Task.checkCancellation() - var additionalData = additionalData.dictionaryAdding(key: jsonKey, value: json) - additionalData = MVMCoreActionHandler.setUUID(additionalData: additionalData, force: true) + let additionalDataWithJSON = additionalData.dictionaryAdding(key: jsonKey, value: json) + let (additionalData, _) = MVMCoreActionHandler.setUUID(additionalData: additionalDataWithJSON, force: true) MVMCoreActionHandler.log(string: "JSON \(json)", additionalData: additionalData) if let closure = (delegateObject?.actionDelegate as? ActionDelegateProtocol)?.performAction { // Allow newer delegates to handle calls from legacy functions diff --git a/MVMCore/MVMCore/Categories/Date+Extension.swift b/MVMCore/MVMCore/Categories/Date+Extension.swift new file mode 100644 index 0000000..3f7df53 --- /dev/null +++ b/MVMCore/MVMCore/Categories/Date+Extension.swift @@ -0,0 +1,16 @@ +// +// Date+Extension.swift +// MVMCore +// +// Created by Kyle on 8/29/22. +// Copyright © 2022 myverizon. All rights reserved. +// + +import Foundation + +public extension Date { + + static func unixMillisecondsNow() -> Int64 { + return Int64(Self().timeIntervalSince1970 * 1000) + } +} diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift new file mode 100644 index 0000000..7db315c --- /dev/null +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -0,0 +1,126 @@ +// +// MVMCoreEvent.swift +// MVMCore +// +// https://oneconfluence.verizon.com/display/MFD/NewRelic+Client+Event+Logging +// +// Created by Kyle on 8/29/22. +// Copyright © 2022 myverizon. All rights reserved. +// + +import Foundation + +/// A list of possible events from the app. +public enum MVMCoreEvent { + + // ---------------------------- + // MARK: Action Events + // ---------------------------- + + /// Failed to decode the action payload. + case actionFailedToDecode( + pageType: String, + error: Error? + ) + + /// Could not find the action specified.. + case actionNotFound( + name: String, + pageType: String + ) + + /// The webview bridge action handler was invoked and is in progress. + case actionInvoked( + name: String, + pageType: String, + uuid: String + ) + + /// The action failed.. + case actionFailed( + name: String, + pageType: String, + uuid: String + ) + + /// The action is completed. + case actionComplete( + name: String, + pageType: String, + uuid: String + ) + + // ---------------------------- + // MARK: ClientParameter Events + // ---------------------------- + + /// Could not find the client parameter specified. + case clientParameterNotFound( + name: String, + pageType: String + ) + + /// The client perameter handler was invoked and is in progress. + case clientParameterFetching( + name: String, + pageType: String, + uuid: String + ) + + /// The client perameter handler timed out and is returning a default value. + case clientParameterTimeout( + name: String, + pageType: String, + uuid: String + ) + + /// The client paramter fetch completed. + case clientParameterComplete( + name: String, + pageType: String, + uuid: String + ) + + public enum EventType: String { + case action + case clientParameter + + public var notification: Notification.Name { + return Notification.Name(rawValue: rawValue) + } + } + + public var type: EventType { + switch self { + case .actionFailedToDecode: return .action + case .actionNotFound: return .action + case .actionInvoked: return .action + case .actionFailed: return .action + case .actionComplete: return .action + case .clientParameterNotFound: return .clientParameter + case .clientParameterFetching: return .clientParameter + case .clientParameterTimeout: return .clientParameter + case .clientParameterComplete: return .clientParameter + } + } + + public var name: String { + let name = String(describing: self) + if let attribIndex = name.firstIndex(of: "(") { + return String(name[.. *)loadedViewController error:(nullable MVMCoreErrorObject *)error; + (void)logAlertForAlertController:(nullable MVMCoreAlertController *)alertController; +- (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes; #pragma mark MVMCoreLoggingDelegateProtocol - (void)handleDebugMessage:(nullable NSString *)message; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m index 766ee3d..9765925 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m @@ -51,6 +51,8 @@ } } +- (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes {} + #pragma mark - logging delegate - (void)handleDebugMessage:(nullable NSString *)message { From 571d55aebd14cdbeb93b145b8617e9fbb59e0e22 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 30 Aug 2022 10:46:38 -0400 Subject: [PATCH 02/68] missing log error call --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index ee7c1ef..dbc76ea 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -176,6 +176,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { switch error { case ModelRegistry.Error.decoderError, is DecodingError: MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionFailedToDecode(pageType: pageType(from: delegateObject), error: error)) + logActionError(error, actionType, additionalData, delegateObject) case ModelRegistry.Error.decoderErrorModelNotMapped: // If the model is not mapped, give the legacy classes a chance to handle it. if try await handleUnregisteredAction(with: nil, json: json!, additionalData: additionalData, delegateObject: delegateObject) == false { From 55d6df4e25db3fce7031585aff715a13f0a79d1b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 30 Aug 2022 17:51:36 -0400 Subject: [PATCH 03/68] client parameter stats changes --- .../ClientParameterHandler.swift | 57 ++++++++++--------- .../MVMCore/OtherHandlers/MVMCoreEvent.swift | 10 +--- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift index 8ead4e1..e64c756 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift @@ -7,16 +7,15 @@ // @objcMembers open class ClientParameterHandler: NSObject { - - var parameterHandlerList: [ClientParameterProtocol] = [] - let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter") - let group = DispatchGroup() + + static let DefaultTimeout = 30.0 open func createParametersHandler(_ clientParameterModel: ClientParameterModelProtocol) -> ClientParameterProtocol? { do { let parameterType = try ModelRegistry.getHandler(clientParameterModel) as! ClientParameterProtocol.Type return parameterType.init(clientParameterModel) } catch { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterNotFound(name: clientParameterModel.type)) if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) { MVMCoreLoggingHandler.addError(toLog: errorObject) } @@ -52,29 +51,29 @@ } open func getParameters(with model: ClientParameterModel, requestParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { - - let timeout = model.timeout ?? 30.0 - + + let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter") + let group = DispatchGroup() + let timeout = model.timeout ?? Self.DefaultTimeout + + let parameterHandlerList = model.list.compactMap { createParametersHandler($0) } + let requestUUID = [0.. [String: AnyHashable] in + guard let parameter = element else { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterTimeout(name: model.list[index].type, uuid: requestUUID[index])) + return parameterHandlerList[index].valueOnTimeout() + } + return parameter + }.reduce(into: [String: AnyHashable]()) { partialResult, next in + partialResult.merge(next) { first, last in first } } - return parametersList } // Setup completion handlers. Barriered to ensure one happens after the other. @@ -92,28 +91,30 @@ } // Setup timeout. - self.parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem) + parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem) // Setup the parameter execution. - for (index, parameterHandler) in self.parameterHandlerList.enumerated() { + for (index, parameterHandler) in parameterHandlerList.enumerated() { let parameterType = parameterHandler.clientParameterModel.type - self.group.enter() + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetching(name: parameterType, uuid: requestUUID[index])) + group.enter() parameterHandler.fetchClientParameters(requestParameters: requestParameters, timingOutIn: timeout) { (receivedParameter) in // Queue the results for merge. - self.parametersWorkQueue.async { + parametersWorkQueue.async { if (returnedList[index] != nil) { MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!) } else { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index])) returnedList[index] = receivedParameter - self.group.leave() // Leaving is only done after setup (barriered). + group.leave() // Leaving is only done after setup (barriered). } } } } // Callback when all parameters have been merged. - self.group.notify(queue: self.parametersWorkQueue, work: completionWorkItem); + group.notify(queue: parametersWorkQueue, work: completionWorkItem); } } } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 7db315c..3d41ea5 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -56,28 +56,24 @@ public enum MVMCoreEvent { /// Could not find the client parameter specified. case clientParameterNotFound( - name: String, - pageType: String + name: String ) /// The client perameter handler was invoked and is in progress. case clientParameterFetching( name: String, - pageType: String, uuid: String ) /// The client perameter handler timed out and is returning a default value. case clientParameterTimeout( name: String, - pageType: String, uuid: String ) /// The client paramter fetch completed. - case clientParameterComplete( + case clientParameterFetchComplete( name: String, - pageType: String, uuid: String ) @@ -100,7 +96,7 @@ public enum MVMCoreEvent { case .clientParameterNotFound: return .clientParameter case .clientParameterFetching: return .clientParameter case .clientParameterTimeout: return .clientParameter - case .clientParameterComplete: return .clientParameter + case .clientParameterFetchComplete: return .clientParameter } } From dfb58e04b697dac0faaae2a0e2772eca3afc2aa9 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 31 Aug 2022 14:34:59 -0400 Subject: [PATCH 04/68] wire in source request UUID for client parameter events --- .../ActionHandling/ActionOpenPageHandler.swift | 10 +++++++--- .../ClientParameterHandler.swift | 16 +++++++++------- MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 16 ++++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 7bdc502..3c0887e 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -44,7 +44,11 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { // Adds any client parameters to the request parameters. if let parametersToFetch = model.clientParameters, - let fetchedParameters = try await ClientParameterHandler().getClientParameters(with: parametersToFetch, requestParameters: requestParameters.parameters as? [String : Any] ?? [:], showLoadingOverlay: !requestParameters.backgroundRequest) { + let fetchedParameters = try await ClientParameterHandler().getClientParameters( + with: parametersToFetch, + requestParameters: requestParameters.parameters as? [String : Any] ?? [:], + actionId: MVMCoreActionHandler.getUUID(additionalData: additionalData) ?? "unknown", + showLoadingOverlay: !requestParameters.backgroundRequest) { requestParameters.add(fetchedParameters) } try Task.checkCancellation() @@ -68,7 +72,7 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { public extension ClientParameterHandler { /// Iterates through the clientParameters list. Gets values from the individual handlers and attaches the parameters to extraParameters. - func getClientParameters(with model: ClientParameterModel, requestParameters: [String: Any], showLoadingOverlay: Bool) async throws -> [String: Any]? { + func getClientParameters(with model: ClientParameterModel, requestParameters: [String: Any], actionId: String, showLoadingOverlay: Bool) async throws -> [String: Any]? { if showLoadingOverlay { MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() } @@ -79,7 +83,7 @@ public extension ClientParameterHandler { } return try await withCheckedThrowingContinuation({ continuation in do { - try getParameters(with: model, requestParameters: requestParameters) { parameters in + try getParameters(with: model, requestParameters: requestParameters, actionId: actionId) { parameters in continuation.resume(returning: parameters) } } catch { diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift index e64c756..a53c062 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift @@ -15,7 +15,6 @@ let parameterType = try ModelRegistry.getHandler(clientParameterModel) as! ClientParameterProtocol.Type return parameterType.init(clientParameterModel) } catch { - MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterNotFound(name: clientParameterModel.type)) if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) { MVMCoreLoggingHandler.addError(toLog: errorObject) } @@ -42,15 +41,15 @@ /// ] ///} /// completionHandler can return flat dictinary or a map. It depends on the paramters handler - open func getParameters(with clientParameters: [String: Any], requestParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { + open func getParameters(with clientParameters: [String: Any], requestParameters: [String: Any], actionId: String, completionHandler:@escaping ([String: Any]?) -> ()) throws { guard let clientParameterModel = try getClientParameterModel(clientParameters) else { completionHandler(nil) return } - try getParameters(with: clientParameterModel, requestParameters: requestParameters, completionHandler: completionHandler) + try getParameters(with: clientParameterModel, requestParameters: requestParameters, actionId: actionId, completionHandler: completionHandler) } - open func getParameters(with model: ClientParameterModel, requestParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { + open func getParameters(with model: ClientParameterModel, requestParameters: [String: Any], actionId: String, completionHandler:@escaping ([String: Any]?) -> ()) throws { let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter") let group = DispatchGroup() @@ -67,7 +66,10 @@ var mergedParametersList: [String: AnyHashable] { return returnedList.enumerated().map { (index, element) -> [String: AnyHashable] in guard let parameter = element else { - MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterTimeout(name: model.list[index].type, uuid: requestUUID[index])) + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterTimeout( + name: model.list[index].type, + uuid: requestUUID[index], + actionId: actionId)) return parameterHandlerList[index].valueOnTimeout() } return parameter @@ -96,7 +98,7 @@ // Setup the parameter execution. for (index, parameterHandler) in parameterHandlerList.enumerated() { let parameterType = parameterHandler.clientParameterModel.type - MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetching(name: parameterType, uuid: requestUUID[index])) + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterStartFetch(name: parameterType, uuid: requestUUID[index], actionId: actionId)) group.enter() parameterHandler.fetchClientParameters(requestParameters: requestParameters, timingOutIn: timeout) { (receivedParameter) in @@ -105,7 +107,7 @@ if (returnedList[index] != nil) { MVMCoreLoggingHandler.addError(toLog: MVMCoreErrorObject(title: nil, message: "Client parameter \(parameterType) has already executed. The completion handler should only be called once!", code: ErrorCode.default.rawValue, domain: ErrorDomainNative, location: String(describing: ClientParameterHandler.self))!) } else { - MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index])) + MVMCoreLoggingHandler.shared()?.logCoreEvent(.clientParameterFetchComplete(name: parameterType, uuid: requestUUID[index], actionId: actionId)) returnedList[index] = receivedParameter group.leave() // Leaving is only done after setup (barriered). } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 3d41ea5..0753ff7 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -56,25 +56,29 @@ public enum MVMCoreEvent { /// Could not find the client parameter specified. case clientParameterNotFound( - name: String + name: String, + actionId: String ) /// The client perameter handler was invoked and is in progress. - case clientParameterFetching( + case clientParameterStartFetch( name: String, - uuid: String + uuid: String, + actionId: String ) /// The client perameter handler timed out and is returning a default value. case clientParameterTimeout( name: String, - uuid: String + uuid: String, + actionId: String ) /// The client paramter fetch completed. case clientParameterFetchComplete( name: String, - uuid: String + uuid: String, + actionId: String ) public enum EventType: String { @@ -94,7 +98,7 @@ public enum MVMCoreEvent { case .actionFailed: return .action case .actionComplete: return .action case .clientParameterNotFound: return .clientParameter - case .clientParameterFetching: return .clientParameter + case .clientParameterStartFetch: return .clientParameter case .clientParameterTimeout: return .clientParameter case .clientParameterFetchComplete: return .clientParameter } From e7e829bb44daa0a1f6aaa295540ff63cb0a0b64d Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 2 Sep 2022 15:49:06 -0400 Subject: [PATCH 05/68] remove deprecated MVMCoreLoadObject code --- .../MVMCore/LoadHandling/MVMCoreLoadObject.h | 9 ----- .../MVMCore/LoadHandling/MVMCoreLoadObject.m | 40 ------------------- 2 files changed, 49 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h index 92063b8..1ee321d 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h @@ -46,7 +46,6 @@ @property (nullable, strong, nonatomic) NSDictionary *dataForPage; // The load delegate -@property (nullable, weak, nonatomic) NSObject *delegate __deprecated; @property (nullable, strong, nonatomic) DelegateObject *delegateObject; // The operation that is loading. @@ -70,12 +69,4 @@ // Returns whether the load will extend the app session timer based on the response provided by the server. - (BOOL)extendsAppSession; -#pragma mark - Deprecated - -- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject*)delegate __deprecated; - -- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject*)delegate __deprecated; - -- (nullable instancetype)initWithDelegate:(nullable NSObject*)delegate __deprecated; - @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m index 9c56d99..25240c4 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m @@ -68,44 +68,4 @@ return NO; } -#pragma mark - Deprecated - -- (void)setDelegateObject:(DelegateObject *)delegateObject { - _delegateObject = delegateObject; - _delegate = delegateObject.loadDelegate; -} - -- (void)setDelegate:(NSObject *)delegate { - _delegate = delegate; - if ([delegate respondsToSelector:@selector(delegateObject)]) { - _delegateObject = [delegate performSelector:@selector(delegateObject)]; - } else { - _delegateObject = [DelegateObject createWithDelegateForAll:delegate]; - } -} - -- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject*)delegate { - - if (self = [self initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate]) { - self.pageJSON = pageJSON; - self.modulesJSON = modulesJSON; - } - return self; -} - -- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject*)delegate { - if (self = [self initWithDelegate:delegate]) { - self.requestParameters = requestParameters; - self.dataForPage = dataForPage; - } - return self; -} - -- (nullable instancetype)initWithDelegate:(nullable NSObject*)delegate { - if (self = [super init]) { - self.delegate = delegate; - } - return self; -} - @end From aff3d52fe8ccf6c4b9087b8efb18cfe9f1a2858f Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Tue, 6 Sep 2022 19:55:16 +0530 Subject: [PATCH 06/68] Adding actiontype attribute to encode in OpenPage action class --- MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift index 611b7b7..34308ef 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift @@ -98,6 +98,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol, public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(pageType, forKey: .pageType) + try container.encode(actionType, forKey: .actionType) try container.encodeIfPresent(baseURL, forKey: .baseURL) try container.encodeIfPresent(appContext, forKey: .appContext) try container.encodeIfPresent(requestURL, forKey: .requestURL) From 13e03375d4664c3743416e7aa770f19361cd26fe Mon Sep 17 00:00:00 2001 From: svc-mips_ios_tower Date: Thu, 8 Sep 2022 10:49:48 -0400 Subject: [PATCH 07/68] Remove bitcode --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index bdd9165..66f3849 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -1131,7 +1131,6 @@ 8876D5D21FB50A9E00EB2E3D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; @@ -1159,7 +1158,6 @@ 8876D5D31FB50A9E00EB2E3D /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - BITCODE_GENERATION_MODE = bitcode; CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; From 61ce51cefdff2c2baa2058708dfb34c717737590 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 13 Sep 2022 21:28:50 +0530 Subject: [PATCH 08/68] setting animatingIn to false --- .../LoadHandling/LoadingOverlay/MVMCoreLoadingOverlayHandler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/LoadingOverlay/MVMCoreLoadingOverlayHandler.m b/MVMCore/MVMCore/LoadHandling/LoadingOverlay/MVMCoreLoadingOverlayHandler.m index d8724af..f3c953e 100644 --- a/MVMCore/MVMCore/LoadHandling/LoadingOverlay/MVMCoreLoadingOverlayHandler.m +++ b/MVMCore/MVMCore/LoadHandling/LoadingOverlay/MVMCoreLoadingOverlayHandler.m @@ -139,7 +139,7 @@ if (animate) { self.animatingOut = YES; - + self.animatingIn = NO; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ self.loadingViewController.view.alpha = 0; } completion:^(BOOL finished) { From 645d30490764c680060cd3f83171ce898a6ce551 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 19 Sep 2022 15:36:16 -0400 Subject: [PATCH 09/68] expose getUUID to obj-c --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index dbc76ea..c37d7a4 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -141,7 +141,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { return (additionalData.dictionaryAdding(key: "Action-UUID", value: newUUID), newUUID) } - static public func getUUID(additionalData: [AnyHashable: Any]?) -> String? { + @objc static public func getUUID(additionalData: [AnyHashable: Any]?) -> String? { return additionalData?.optionalStringForKey("Action-UUID") } From 793e64143dc7a5b5a2609a923ac9eccce4fab3a4 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Tue, 20 Sep 2022 17:29:38 -0400 Subject: [PATCH 10/68] copy fix --- MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 3c0887e..0267ea4 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -13,11 +13,12 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { open func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { guard let model = model as? ActionOpenPageModel else { return } + let requestParameters: MVMCoreRequestParameters = model.requestParameters.copy() as! MVMCoreRequestParameters do { if let closure = delegateObject?.actionDelegate?.handleOpenPage { // Legacy code will use the old handler function and break the task chain here. - closure(model.requestParameters, JSON, additionalData) - } else if let operation = try await performRequestAddingClientParameters(with: model.requestParameters, model: model, delegateObject: delegateObject, additionalData: additionalData) { + closure(requestParameters, JSON, additionalData) + } else if let operation = try await performRequestAddingClientParameters(with: requestParameters, model: model, delegateObject: delegateObject, additionalData: additionalData) { await withCheckedContinuation { continuation in operation.completionBlock = { continuation.resume() From 89d9809b9ebb164c7241ea8f386aa4dbf18ed1c8 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 23 Sep 2022 18:34:19 -0400 Subject: [PATCH 11/68] add error description to JSONErrors --- MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index a0c20d0..775048d 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -18,6 +18,30 @@ public enum JSONError: Error { case error(message: String) } +extension JSONError: LocalizedError, CustomStringConvertible { + + public var description: String { + switch self { + case .pathNotFound: + return "JSON path not found" + case .data(path: let path): + return "JSON data in \(path) is corrupt" + case .other(error: let error): + if let decodingError = error as? DecodingError { + // the only way to get the decoding error description and details... + return (decodingError as NSError).description + } + return error.localizedDescription + case .error(message: let message): + return message + } + } + + public var errorDescription: String? { + return description + } +} + extension JSONDictionary { public func toJSONString(options: JSONSerialization.WritingOptions = []) throws -> String { From ec70621ea088f3a89e20a47a9f814f04163f25d1 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Wed, 28 Sep 2022 10:15:57 +0530 Subject: [PATCH 12/68] Changed to read and set requestUrl in restart action. --- MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift | 2 +- MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift | 4 +++- MVMCore/MVMCore/Session/MVMCoreSessionObject.h | 2 +- MVMCore/MVMCore/Session/MVMCoreSessionObject.m | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index 20e7a90..8e1e56f 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -26,7 +26,7 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { continuation.resume(throwing: MVMCoreError.errorObject(error)) } else { // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, parameters: model.extraParameters.toJSON(), clearAllVariables: true) + MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, requestUrl: model.requestUrl, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) continuation.resume() } }) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index 7cc2d26..fee5496 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -14,6 +14,7 @@ public struct ActionRestartModel: ActionModelProtocol { public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier + public var requestUrl: String? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -24,8 +25,9 @@ public struct ActionRestartModel: ActionModelProtocol { // MARK: - Initializer //-------------------------------------------------- - public init(_ pageType: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + public init(_ pageType: String? = nil, _ requestUrl: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType + self.requestUrl = requestUrl self.extraParameters = extraParameters self.analyticsData = analyticsData } diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h index 8c86697..e82fa04 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h @@ -36,7 +36,7 @@ - (nullable NSDictionary *)getInitialParametersExcludingSections:(nullable NSSet *)excludeSections; /// Restarts the application session state. Can clear variables and pass a page type if needed. -- (void)restartSessionWithPageType:(nullable NSString *)pageType parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; /// Redirect, leaving the current app experience. - (void)redirectWithInfo:(nullable NSDictionary *)dictionary; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index bcdf390..c52913d 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -36,7 +36,7 @@ return nil; } -- (void)restartSessionWithPageType:(nullable NSString *)pageType parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString*)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { // Clears the singletons of any session related data. if (clearAllVariables) { [self clearSessionObject]; From de280960f7fcb53bd31c92e6bed24b7abfe05f10 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 3 Oct 2022 11:32:49 -0400 Subject: [PATCH 13/68] copy over the actionMap to the new object for presentationStyle resolution fix. --- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index 63f4f4f..e07070a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -152,6 +152,7 @@ copyObject.customTimeoutTime = self.customTimeoutTime; copyObject.backgroundRequest = self.backgroundRequest; copyObject.URL = self.URL; + copyObject.actionMap = self.actionMap; return copyObject; } From cdd2eb2f0493e61e02e774551749e103643bc8a6 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 14 Oct 2022 12:27:15 +0530 Subject: [PATCH 14/68] fixed crash array out of bounds exception --- .../ActionType/Client Parameters/ClientParameterHandler.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift index a53c062..f0d78c2 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterHandler.swift @@ -56,7 +56,7 @@ let timeout = model.timeout ?? Self.DefaultTimeout let parameterHandlerList = model.list.compactMap { createParametersHandler($0) } - let requestUUID = [0.. Date: Fri, 14 Oct 2022 22:54:25 +0530 Subject: [PATCH 15/68] Change the requestUrl param key --- MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift | 2 +- MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index 8e1e56f..a2c7241 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -26,7 +26,7 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { continuation.resume(throwing: MVMCoreError.errorObject(error)) } else { // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, requestUrl: model.requestUrl, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) + MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, requestUrl: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) continuation.resume() } }) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index fee5496..c9fa9b6 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -14,7 +14,7 @@ public struct ActionRestartModel: ActionModelProtocol { public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier - public var requestUrl: String? + public var requestURL: String? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -27,7 +27,7 @@ public struct ActionRestartModel: ActionModelProtocol { public init(_ pageType: String? = nil, _ requestUrl: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType - self.requestUrl = requestUrl + self.requestURL = requestUrl self.extraParameters = extraParameters self.analyticsData = analyticsData } From 85dcc5751328767397b079a2b98636d18961be25 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Mon, 17 Oct 2022 17:52:43 +0530 Subject: [PATCH 16/68] Changing the requestURL type to NSURL from NSString --- .../ActionHandling/ActionRestartHandler.swift | 2 +- .../ActionHandling/ActionRestartModel.swift | 36 +++++++++++++++++-- .../MVMCore/Session/MVMCoreSessionObject.h | 2 +- .../MVMCore/Session/MVMCoreSessionObject.m | 2 +- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index a2c7241..29fbf53 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -26,7 +26,7 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { continuation.resume(throwing: MVMCoreError.errorObject(error)) } else { // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, requestUrl: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) + MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) continuation.resume() } }) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index c9fa9b6..30888f9 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -6,6 +6,7 @@ // Copyright © 2020 myverizon. All rights reserved. // +import Foundation public struct ActionRestartModel: ActionModelProtocol { //-------------------------------------------------- @@ -14,7 +15,7 @@ public struct ActionRestartModel: ActionModelProtocol { public static var identifier: String = "restart" public var actionType: String = ActionRestartModel.identifier - public var requestURL: String? + public var requestURL: URL? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? @@ -25,10 +26,41 @@ public struct ActionRestartModel: ActionModelProtocol { // MARK: - Initializer //-------------------------------------------------- - public init(_ pageType: String? = nil, _ requestUrl: String? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { + public init(_ pageType: String? = nil, _ requestUrl: URL? = nil, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { self.pageType = pageType self.requestURL = requestUrl self.extraParameters = extraParameters self.analyticsData = analyticsData } + + //-------------------------------------------------- + // MARK: - Codable + //-------------------------------------------------- + private enum CodingKeys: String, CodingKey { + case actionType + case requestURL + case extraParameters + case analyticsData + case pageType + } + + public init(from decoder: Decoder) throws { + + let container = try decoder.container(keyedBy: CodingKeys.self) + self.actionType = try container.decode(String.self, forKey: .actionType) + self.requestURL = try container.decodeIfPresent(URL.self, forKey: .requestURL) + self.extraParameters = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters) + self.analyticsData = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData) + self.pageType = try container.decodeIfPresent(String.self, forKey: .pageType) + } + + public func encode(to encoder: Encoder) throws { + + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(actionType, forKey: .actionType) + try container.encodeIfPresent(requestURL, forKey: .requestURL) + try container.encodeIfPresent(extraParameters, forKey: .extraParameters) + try container.encodeIfPresent(analyticsData, forKey: .analyticsData) + try container.encode(pageType, forKey: .pageType) + } } diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h index e82fa04..2f676b0 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.h @@ -36,7 +36,7 @@ - (nullable NSDictionary *)getInitialParametersExcludingSections:(nullable NSSet *)excludeSections; /// Restarts the application session state. Can clear variables and pass a page type if needed. -- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSURL *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables; /// Redirect, leaving the current app experience. - (void)redirectWithInfo:(nullable NSDictionary *)dictionary; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index c52913d..e5bed5e 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -36,7 +36,7 @@ return nil; } -- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSString*)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { +- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSURL *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables { // Clears the singletons of any session related data. if (clearAllVariables) { [self clearSessionObject]; From 8dd0aebf7e06841ef1399e9438f3ee3a51efaaa7 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 20 Oct 2022 16:19:47 -0400 Subject: [PATCH 17/68] always embed swift to no --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 67792ea..673f872 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -1015,7 +1015,6 @@ 8876D5CF1FB50A9E00EB2E3D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_SEARCH_USER_PATHS = NO; BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; @@ -1079,7 +1078,6 @@ 8876D5D01FB50A9E00EB2E3D /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_SEARCH_USER_PATHS = NO; BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; From 217cceb84bab7561640f5f0463beaebc6fff461e Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Tue, 25 Oct 2022 20:04:32 +0530 Subject: [PATCH 18/68] Removing the codable method for the restart action type --- .../ActionHandling/ActionRestartModel.swift | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift index 30888f9..e64a6d3 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartModel.swift @@ -32,35 +32,4 @@ public struct ActionRestartModel: ActionModelProtocol { self.extraParameters = extraParameters self.analyticsData = analyticsData } - - //-------------------------------------------------- - // MARK: - Codable - //-------------------------------------------------- - private enum CodingKeys: String, CodingKey { - case actionType - case requestURL - case extraParameters - case analyticsData - case pageType - } - - public init(from decoder: Decoder) throws { - - let container = try decoder.container(keyedBy: CodingKeys.self) - self.actionType = try container.decode(String.self, forKey: .actionType) - self.requestURL = try container.decodeIfPresent(URL.self, forKey: .requestURL) - self.extraParameters = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters) - self.analyticsData = try container.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData) - self.pageType = try container.decodeIfPresent(String.self, forKey: .pageType) - } - - public func encode(to encoder: Encoder) throws { - - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(actionType, forKey: .actionType) - try container.encodeIfPresent(requestURL, forKey: .requestURL) - try container.encodeIfPresent(extraParameters, forKey: .extraParameters) - try container.encodeIfPresent(analyticsData, forKey: .analyticsData) - try container.encode(pageType, forKey: .pageType) - } } From d7b80e87edcfbab7692352c4b19b4307a11d5294 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 26 Oct 2022 20:44:18 -0400 Subject: [PATCH 19/68] fix user facing error message for json errors --- MVMCore/MVMCore/Models/JSON/JSONHelper.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift index 775048d..857310b 100644 --- a/MVMCore/MVMCore/Models/JSON/JSONHelper.swift +++ b/MVMCore/MVMCore/Models/JSON/JSONHelper.swift @@ -37,8 +37,9 @@ extension JSONError: LocalizedError, CustomStringConvertible { } } + // Shown to customers. public var errorDescription: String? { - return description + return MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess) } } From 11728703ce2cda935414eee0bc417e081698e853 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 28 Oct 2022 10:07:36 -0400 Subject: [PATCH 20/68] Add back legacy error code --- MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift index 5ed9d2d..085b9a4 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenUrlHandler.swift @@ -40,6 +40,10 @@ open class ActionOpenUrlHandler: MVMCoreJSONActionHandlerProtocol { return "Failed to open url: \(url.absoluteString)" } } + + public var errorCode: Int { + return ErrorCode.linkawayFailed.rawValue + } } /// Creates a url and calls open(url: URL) From 6874424dd19dcbf0933ad302eb30cf34181af0ef Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Mon, 12 Dec 2022 13:58:39 +0530 Subject: [PATCH 21/68] added supportedInterfaceOrientations in MVMCoreAlertController --- MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m index 673c591..11c6fd2 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m @@ -8,6 +8,7 @@ #import "MVMCoreAlertController.h" #import "MVMCoreLoggingHandler.h" +#import "MVMCoreGetterUtility.h" @interface MVMCoreAlertController () @@ -37,4 +38,12 @@ return [NSString stringWithFormat:@"%@|title=%@|message=%@", [super description],self.title,self.message]; } +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + if ([MVMCoreGetterUtility isOnIPad]) { + return UIInterfaceOrientationMaskAll; + } else { + return UIInterfaceOrientationMaskPortrait; + } +} + @end From 920b9752946dac40898adc43689a40bb526f450e Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 27 Dec 2022 16:47:41 -0500 Subject: [PATCH 22/68] expose method to report the final load operation source --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h | 1 + MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h index ab87548..1a9f80a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h @@ -22,6 +22,7 @@ @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; @property (nullable, strong, nonatomic) NSDictionary *dataForPage; @property (nullable, strong, nonatomic) DelegateObject *delegateObject; +@property (nullable, nonatomic, readonly) NSString *finalLoadSource; @property (nonatomic) BOOL backgroundLoad; @property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index d48d53f..48f104c 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -77,6 +77,10 @@ [super start]; } +- (NSString *)finalLoadSource { + return _sessionTask.currentRequest.URL.absoluteString; +} + - (void)markAsFinished { // stop any loading animation we may have started From aa1be3f1c59ca0cf13a3c73dfba5bd543ccae0ea Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 28 Dec 2022 10:23:10 -0500 Subject: [PATCH 23/68] Fix isAppInSession and appEnteredForeground collision. Fix FaceId session timer restart skip. Encapsulate timeTimerStarted referenceDate. --- .../Session/MVMCoreSessionTimeHandler.h | 37 +++--- .../Session/MVMCoreSessionTimeHandler.m | 107 ++++++++++-------- 2 files changed, 79 insertions(+), 65 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h index d31ae62..99ee577 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h @@ -13,50 +13,57 @@ @interface MVMCoreSessionTimeHandler : NSObject -// The time that we started the last session timer. -@property (assign, nonatomic, readonly) NSTimeInterval timeTimerStarted; +/// The number of seconds ago that we started the last session timer. Distant past if it wasn't started. +@property (nonatomic, readonly) NSTimeInterval timeSinceStart; -// Keeps track of if the session is currently being timed. Used for entering from the background. +/// The number of seconds remaining until a warning will occur. +@property (nonatomic, readonly) NSTimeInterval remainingTimeUntilWarning; + +/// The number of seconds remaining until a timeout will occur. +@property (nonatomic, readonly) NSTimeInterval remainingTimeUntiTimeout; + + +/// Keeps track of if the session is currently being timed. Used for entering from the background. @property (assign, nonatomic, readonly) BOOL sessionBeingTimed; -// Keeps track of if the session has already timed out. +/// Keeps track of if the session has already timed out. @property (assign, nonatomic, readonly) BOOL sessionTimedOut; #pragma mark - functions to override -// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0 +/// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0 - (NSTimeInterval)timeUntilWarning; -// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0. +/// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0. - (NSTimeInterval)timeUntilTimeout; -// Starts the timeout timer. Override to handle what happens on timeout warning. Should call super if want the timeout timer going. +/// Starts the timeout timer. Override to handle what happens on timeout warning. Should call super if want the timeout timer going. - (void)sessionTimeoutWarning NS_REQUIRES_SUPER; -// Called when the session has timed out. Override to handle what happens on timeout. Should call super. Can be called to force timeout... should never need to call unless simulating timout. +/// Called when the session has timed out. Override to handle what happens on timeout. Should call super. Can be called to force timeout... should never need to call unless simulating timout. - (void)sessionTimeout:(BOOL)whileInBackground NS_REQUIRES_SUPER; -// Keeps the session alive. A boolean for if we should show the alert if there is an error. Does nothing by default. Can override to do something. +/// Keeps the session alive. A boolean for if we should show the alert if there is an error. Does nothing by default. Can override to do something. - (void)sendKeepAliveToServer:(BOOL)notifyUserIfError; -// Invalidates the server session and then calls the completion handler. Error may or may not populate. By default this only calls the completion handler, override to invalidate your server session as you see fit then call completion. +/// Invalidates the server session and then calls the completion handler. Error may or may not populate. By default this only calls the completion handler, override to invalidate your server session as you see fit then call completion. - (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion; #pragma mark - Session timer functions -// Returns the shared instance of this singleton +/// Returns the shared instance of this singleton + (nullable instancetype)sharedSessionHandler; -// Starts the session timer. Should be called after every response from the server. Happens on the main thread. +/// Starts the session timer. Should be called after every response from the server. Happens on the main thread. - (void)startSessionTimer; -// Should only be used in rare occassions, like on the original wifi screen. +/// Completely stop the session timer. Should only be used in rare occassions, like on the original wifi screen. - (void)stopSessionTimer; -// Returns whether the app is in session. +/// Returns whether the app is in session. - (BOOL)isAppInSession; -// Resets everything. +/// Resets everything. - (void)resetState; @end diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index f0bf1b5..be90025 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -24,22 +24,22 @@ @property (strong, nonatomic) NSTimer *sessionWarningTimer; @property (strong, nonatomic) NSTimer *sessionTimer; -// The time that we started the last session timer. +/// The time that we started the last session timer. @property (assign, nonatomic, readwrite) NSTimeInterval timeTimerStarted; -// Keeps track of if the session is currently being timed. Used for entering from the background. +/// Keeps track of if the session is currently being timed. Used for entering from the background. @property (assign, nonatomic, readwrite) BOOL sessionBeingTimed; -// Keeps track of if the session has already timed out. +/// Keeps track of if the session has already timed out. @property (assign, nonatomic, readwrite) BOOL sessionTimedOut; @property (assign, nonatomic) NSTimeInterval secondsUntilWarning; @property (assign, nonatomic) NSTimeInterval secondsUntilTimeout; -// Should be called when the app enters the background. +/// Should be called when the app enters the background. - (void)appEnteredBackground; -// Should be called when the app enters the foreground. +/// Should be called when the app enters the foreground. - (void)appEnteredForeground; @end @@ -55,6 +55,7 @@ // Adds notifications for if the app entered the background/foreground. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; + [self resetStartTime]; } return self; } @@ -85,6 +86,28 @@ - (void)sendKeepAliveToServer:(BOOL)notifyUserIfError { } +#pragma mark - State + +- (void)markStartTime { + self.timeTimerStarted = [NSDate timeIntervalSinceReferenceDate]; +} + +- (void)resetStartTime { + self.timeTimerStarted = [[NSDate distantPast] timeIntervalSinceReferenceDate]; +} + +- (NSTimeInterval)timeSinceStart { + return [NSDate timeIntervalSinceReferenceDate] - self.timeTimerStarted; +} + +- (NSTimeInterval)remainingTimeUntilWarning { + return self.secondsUntilWarning - self.timeSinceStart; +} + +- (NSTimeInterval)remainingTimeUntiTimeout { + return self.secondsUntilTimeout - self.timeSinceStart; +} + #pragma mark - Session timer functions - (void)startSessionTimer { @@ -97,22 +120,34 @@ self.secondsUntilWarning = [self timeUntilWarning]; self.secondsUntilTimeout = [self timeUntilTimeout]; + if (!fequal(0, self.secondsUntilTimeout)) { self.sessionBeingTimed = YES; - self.timeTimerStarted = [NSDate timeIntervalSinceReferenceDate]; - } - - // Only start physical timer if active, otherwise will begin once entering foreground. - if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && !fequal(0, self.secondsUntilTimeout)) { - if (!fequal(0, self.secondsUntilWarning)) { - self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:self.secondsUntilWarning target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; + [self markStartTime]; + + // Only start physical timer if active, otherwise will begin once entering foreground. FaceId prompt is considered UIApplicationStateInactive. + if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { + [self resumeSessionTimer]; } - self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:self.secondsUntilTimeout target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; } } }); } +/// Resume the session timers if they are stopped. +- (void)resumeSessionTimer { + dispatch_async(dispatch_get_main_queue(), ^(void) { + if (!fequal(0, self.secondsUntilWarning) && ![self.sessionWarningTimer isValid]) { + self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; + MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); + } + if (!fequal(0, self.secondsUntilTimeout) && ![self.sessionTimer isValid]) { + self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntiTimeout] target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; + MVMCoreLog(@"Session timeout will fire at: %@", self.sessionTimer.fireDate); + } + }); +} + - (void)stopSessionTimer { // nil timer, session no longer timed. @@ -137,31 +172,7 @@ } - (void)appEnteredForeground { - - if (self.sessionBeingTimed || self.sessionTimedOut) { - - NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; - if ((!fequal(0, self.secondsUntilWarning) && now > self.timeTimerStarted + self.secondsUntilWarning) || (!fequal(0, self.secondsUntilTimeout) && now > self.timeTimerStarted + self.secondsUntilTimeout)) { - - // Timeout if we are passed the warning. - [self sessionTimeout:YES]; - } else { - if (!fequal(0, self.secondsUntilWarning)) { - - // Restart the warning timer! - NSTimeInterval timeLeftTillWarning = self.timeTimerStarted + self.secondsUntilWarning - now; - [self.sessionWarningTimer invalidate]; - self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:timeLeftTillWarning target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; - } - if (!fequal(0, self.secondsUntilTimeout)) { - - // Restart the timeout timer! - NSTimeInterval timeLeftTillTimeout = self.timeTimerStarted + self.secondsUntilTimeout - now; - [self.sessionTimer invalidate]; - self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:timeLeftTillTimeout target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; - } - } - } + [self revalidateSessionTimestamp]; } - (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion { @@ -170,18 +181,14 @@ // Checks to make sure session is still valid and that the timer is running. - (void)revalidateSessionTimestamp { - if (self.sessionBeingTimed && !self.sessionTimedOut) { - - NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; - if ((!fequal(0, self.secondsUntilWarning) && now > self.timeTimerStarted + self.secondsUntilWarning) || (!fequal(0, self.secondsUntilTimeout) && now > self.timeTimerStarted + self.secondsUntilTimeout)) { - self.sessionTimedOut = YES; - [self.sessionWarningTimer invalidate]; - self.sessionWarningTimer = nil; - [self.sessionTimer invalidate]; - self.sessionTimer = nil; - } else if (![self.sessionTimer isValid]) { - // Restart the session timer! - [self startSessionTimer]; + if (self.sessionBeingTimed || self.sessionTimedOut) { + NSTimeInterval timeSinceStart = [self timeSinceStart]; + if ((!fequal(0, self.secondsUntilWarning) && timeSinceStart > self.secondsUntilWarning) || (!fequal(0, self.secondsUntilTimeout) && timeSinceStart > self.secondsUntilTimeout)) { + + // Timeout if we are passed the warning. + [self sessionTimeout:YES]; + } else { + [self resumeSessionTimer]; } } } From c7bfda216a79c04689894754c16935bc9a41165e Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 28 Dec 2022 10:54:31 -0500 Subject: [PATCH 24/68] Trigger a keep alive attempt when returning from background. --- MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index be90025..0ab40c8 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -172,7 +172,9 @@ } - (void)appEnteredForeground { + // Revalidate first to check if we should be in the timeout state. [self revalidateSessionTimestamp]; + [self sendKeepAliveToServer:NO]; } - (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion { From 80512a0b8aadd9f3bd3f1b56123320bd29842147 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 28 Dec 2022 11:02:02 -0500 Subject: [PATCH 25/68] Shift app background check to resumeSessionTimer to make isAppInSession and revalidateSessionTimestamp background safe. --- MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index 0ab40c8..84dbc0f 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -124,11 +124,7 @@ if (!fequal(0, self.secondsUntilTimeout)) { self.sessionBeingTimed = YES; [self markStartTime]; - - // Only start physical timer if active, otherwise will begin once entering foreground. FaceId prompt is considered UIApplicationStateInactive. - if ([UIApplication sharedApplication].applicationState != UIApplicationStateBackground) { - [self resumeSessionTimer]; - } + [self resumeSessionTimer]; } } }); @@ -137,6 +133,11 @@ /// Resume the session timers if they are stopped. - (void)resumeSessionTimer { dispatch_async(dispatch_get_main_queue(), ^(void) { + // Only start physical timer if active, otherwise will begin once entering foreground. FaceId prompt is considered UIApplicationStateInactive. + if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { + return; + } + if (!fequal(0, self.secondsUntilWarning) && ![self.sessionWarningTimer isValid]) { self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); From 16d169c46c4f9816f45da76ce552d958b73f0286 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 13 Jan 2023 18:57:23 -0500 Subject: [PATCH 26/68] Code review suggestion to use default values. Bug fix for warning track timeouts from the background. --- .../Session/MVMCoreSessionTimeHandler.h | 7 ++- .../Session/MVMCoreSessionTimeHandler.m | 47 ++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h index 99ee577..cb4db62 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h @@ -13,16 +13,15 @@ @interface MVMCoreSessionTimeHandler : NSObject -/// The number of seconds ago that we started the last session timer. Distant past if it wasn't started. +/// The number of seconds ago that we started the last session timer. A value of -1 will be returned for sessions not started. @property (nonatomic, readonly) NSTimeInterval timeSinceStart; -/// The number of seconds remaining until a warning will occur. +/// The number of seconds remaining until a warning will occur. A value of 0 will be returned for sessions not started or warning tracking is not enabled. @property (nonatomic, readonly) NSTimeInterval remainingTimeUntilWarning; -/// The number of seconds remaining until a timeout will occur. +/// The number of seconds remaining until a timeout will occur. A value of 0 will be returned for sessions not started or timeout tracking is not enabled. @property (nonatomic, readonly) NSTimeInterval remainingTimeUntiTimeout; - /// Keeps track of if the session is currently being timed. Used for entering from the background. @property (assign, nonatomic, readonly) BOOL sessionBeingTimed; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index 84dbc0f..191c3a8 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -93,18 +93,35 @@ } - (void)resetStartTime { - self.timeTimerStarted = [[NSDate distantPast] timeIntervalSinceReferenceDate]; + self.timeTimerStarted = -1; } - (NSTimeInterval)timeSinceStart { + if (self.timeTimerStarted < 0) { + return -1; + } return [NSDate timeIntervalSinceReferenceDate] - self.timeTimerStarted; } +- (BOOL)isWarningEnabled { + return !fequal(0, self.secondsUntilWarning); +} + +- (BOOL)isTimeoutEnabled { + return !fequal(0, self.secondsUntilTimeout); +} + - (NSTimeInterval)remainingTimeUntilWarning { + if (self.timeTimerStarted < 0 || ![self isTimeoutEnabled]) { + return 0; + } return self.secondsUntilWarning - self.timeSinceStart; } - (NSTimeInterval)remainingTimeUntiTimeout { + if (self.timeTimerStarted < 0 || ![self isTimeoutEnabled]) { + return 0; + } return self.secondsUntilTimeout - self.timeSinceStart; } @@ -121,7 +138,7 @@ self.secondsUntilWarning = [self timeUntilWarning]; self.secondsUntilTimeout = [self timeUntilTimeout]; - if (!fequal(0, self.secondsUntilTimeout)) { + if (self.isTimeoutEnabled) { self.sessionBeingTimed = YES; [self markStartTime]; [self resumeSessionTimer]; @@ -137,14 +154,17 @@ if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { return; } - - if (!fequal(0, self.secondsUntilWarning) && ![self.sessionWarningTimer isValid]) { - self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; - MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); - } - if (!fequal(0, self.secondsUntilTimeout) && ![self.sessionTimer isValid]) { + + if (self.isTimeoutEnabled && ![self.sessionTimer isValid]) { + // Session timeout, implicitly whileInBackround as no. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntiTimeout] target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; MVMCoreLog(@"Session timeout will fire at: %@", self.sessionTimer.fireDate); + + // Only setup a warning timer if there is a timout timer. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. + if (self.isWarningEnabled && ![self.sessionWarningTimer isValid]) { + self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; + MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); + } } }); } @@ -173,6 +193,11 @@ } - (void)appEnteredForeground { + // Special return logic to cancel when returning in warning track. This is not in the revalidateSessionTimestamp in order to prevent API checks to isAppInSession from timing out the session from under the user warning period. + if (self.isWarningEnabled && self.remainingTimeUntilWarning < 0) { + [self sessionTimeout:YES]; + } + // Revalidate first to check if we should be in the timeout state. [self revalidateSessionTimestamp]; [self sendKeepAliveToServer:NO]; @@ -185,9 +210,7 @@ // Checks to make sure session is still valid and that the timer is running. - (void)revalidateSessionTimestamp { if (self.sessionBeingTimed || self.sessionTimedOut) { - NSTimeInterval timeSinceStart = [self timeSinceStart]; - if ((!fequal(0, self.secondsUntilWarning) && timeSinceStart > self.secondsUntilWarning) || (!fequal(0, self.secondsUntilTimeout) && timeSinceStart > self.secondsUntilTimeout)) { - + if (self.isTimeoutEnabled && self.remainingTimeUntiTimeout < 0) { // Timeout if we are passed the warning. [self sessionTimeout:YES]; } else { @@ -197,7 +220,7 @@ } - (BOOL)isAppInSession { - [self revalidateSessionTimestamp]; + [self revalidateSessionTimestamp]; // Possible race condition hazard. Session timeouts will happen as if they are in background. If isAppInSession is called right before foreground trigger, it could potentially suppress the dialog. return self.sessionBeingTimed && !self.sessionTimedOut; } From 1f377dfb515437f8fb1f776f0aa89106dabc77f8 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 17 Jan 2023 12:10:43 -0500 Subject: [PATCH 27/68] remainingWarningTime fix. code comment cleanups. --- MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h | 2 +- MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h index cb4db62..04e2eeb 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h @@ -30,7 +30,7 @@ #pragma mark - functions to override -/// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0 +/// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0. - (NSTimeInterval)timeUntilWarning; /// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0. diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index 191c3a8..6d6e9cd 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -104,7 +104,7 @@ } - (BOOL)isWarningEnabled { - return !fequal(0, self.secondsUntilWarning); + return [self isTimeoutEnabled] && !fequal(0, self.secondsUntilWarning); } - (BOOL)isTimeoutEnabled { @@ -112,7 +112,7 @@ } - (NSTimeInterval)remainingTimeUntilWarning { - if (self.timeTimerStarted < 0 || ![self isTimeoutEnabled]) { + if (self.timeTimerStarted < 0 || ![self isWarningEnabled]) { return 0; } return self.secondsUntilWarning - self.timeSinceStart; @@ -160,7 +160,7 @@ self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntiTimeout] target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; MVMCoreLog(@"Session timeout will fire at: %@", self.sessionTimer.fireDate); - // Only setup a warning timer if there is a timout timer. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. + // Only setup a warning timer if there is a timeout timer. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. if (self.isWarningEnabled && ![self.sessionWarningTimer isValid]) { self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); @@ -211,7 +211,7 @@ - (void)revalidateSessionTimestamp { if (self.sessionBeingTimed || self.sessionTimedOut) { if (self.isTimeoutEnabled && self.remainingTimeUntiTimeout < 0) { - // Timeout if we are passed the warning. + // Force a timeout if we are passed the timeout interval. [self sessionTimeout:YES]; } else { [self resumeSessionTimer]; From 3e9d66e5e0c65e331bb158dc0d16cc1e06d7cfd9 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Thu, 26 Jan 2023 19:03:10 -0500 Subject: [PATCH 28/68] add missing event data --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift | 1 + MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index c37d7a4..0e751a7 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -114,6 +114,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { throw ActionError.unknownAction(type: model.actionType) } } catch { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.actionFailed(name: model.actionType, pageType: pageType(from: delegateObject), uuid: uuid, error: error)) MVMCoreActionHandler.log(string: "Failed Action \(error)", additionalData: additionalData) throw error } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 0753ff7..73d8ecc 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -40,7 +40,8 @@ public enum MVMCoreEvent { case actionFailed( name: String, pageType: String, - uuid: String + uuid: String, + error: Error? ) /// The action is completed. From 74c16205e186cf6875983c25b4fea19d6a4c23b1 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 16 Feb 2023 17:15:47 -0500 Subject: [PATCH 29/68] update artifactory url from prod to ci --- .gitlab-ci.yml | 8 ++++---- Scripts/upload_core_frameworks.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bf618fd..dac0562 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,9 +31,9 @@ deploy_snapshot: - bash_shell environment: name: oneartifactory - url: https://oneartifactoryprod.verizon.com/artifactory + url: https://oneartifactoryci.verizon.com/artifactory variables: - ARTIFACTORY_URL: https://oneartifactoryprod.verizon.com/artifactory + ARTIFACTORY_URL: https://oneartifactoryci.verizon.com/artifactory #promote_snapshot: # stage: go live @@ -49,9 +49,9 @@ deploy_snapshot: # - bash_shell # environment: # name: oneartifactory -# url: https://oneartifactoryprod.verizon.com/artifactory +# url: https://oneartifactoryci.verizon.com/artifactory # variables: -# ARTIFACTORY_URL: https://oneartifactoryprod.verizon.com/artifactory +# ARTIFACTORY_URL: https://oneartifactoryci.verizon.com/artifactory # #create_version_tag: # stage: tag diff --git a/Scripts/upload_core_frameworks.sh b/Scripts/upload_core_frameworks.sh index 9067da5..f7b74be 100755 --- a/Scripts/upload_core_frameworks.sh +++ b/Scripts/upload_core_frameworks.sh @@ -17,7 +17,7 @@ fi # Create new aggregate builds if [ -z $ARTIFACTORY_URL ]; then - ARTIFACTORY_URL="https://oneartifactoryprod.verizon.com/artifactory" + ARTIFACTORY_URL="https://oneartifactoryci.verizon.com/artifactory" fi BUILD_DIR=$(echo "$BUILD_SETTINGS" | grep -w -o 'BUILD_DIR = .*' | cut -d\ -f3-) From 5006517bb11b708e866cd649294f851b4c8af07b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Sat, 25 Feb 2023 00:20:55 -0500 Subject: [PATCH 30/68] wrapper function to add additoinal request data to error objects. begin working on better silentError handling. --- .../MVMCore/Constants/MVMCoreErrorConstants.m | 4 ++ .../MVMCore/LoadHandling/MVMCoreLoadHandler.h | 9 ++++ .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 21 +++++++-- .../MVMCoreLoadRequestOperation.h | 1 + .../MVMCoreLoadRequestOperation.m | 26 +++++++---- MVMCore/MVMCore/Utility/MVMCoreErrorObject.h | 5 +++ MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 43 ++++++++----------- 7 files changed, 71 insertions(+), 38 deletions(-) diff --git a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m index d626352..e9028ff 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m @@ -9,6 +9,10 @@ #import "MVMCoreErrorConstants.h" // Error Domains + +/// Communication breakddowns. NSString * const ErrorDomainSystem = @"ErrorDomainSystem"; +/// Any sort of native error not due to server directivees. NSString * const ErrorDomainNative = @"ErrorDomainNative"; +/// Specific errors defined by the server. NSString * const ErrorDomainServer = @"ErrorDomainServer"; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h index 84de194..93e7404 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h @@ -33,6 +33,15 @@ // Returns the error location for the given requesting object and page type and modules. Important for proper logging. - (nonnull NSString *)errorLocationForRequest:(nonnull id)requestingObject pageType:(nonnull NSString *)pageType modules:(nonnull NSString *)modules; +// Returns an error given a load object and error details. Attaches session data related to the load. Important for proper logging. +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(nonnull MVMCoreLoadObject *)loadObject withTitle:(nullable NSString *)title message:(nullable NSString *)message code:(NSInteger)code domain:(nonnull NSString *)domain; + +// Returns an error given a load object and NSError. Attaches session data related to the load. Important for proper logging. +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(nonnull MVMCoreLoadObject *)loadObject causedBy:(nonnull NSError *)error; + +// Decorates an error object given a load object. +- (nonnull MVMCoreErrorObject *)attachLoadInformation:(nonnull MVMCoreLoadObject *)loadObject toError:(nonnull MVMCoreErrorObject *)error; + #pragma mark - Request Functions. - (void)setHeadersForRequest:(nonnull NSMutableURLRequest *)request requestParameters:(nonnull MVMCoreRequestParameters *)requestParameters; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 842d032..e5eb99d 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -95,9 +95,22 @@ } } +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(MVMCoreLoadObject *)loadObject withTitle:(NSString *)title message:(NSString *)message code:(NSInteger)code domain:(NSString *)domain { + return [self attachLoadInformation:loadObject toError:[[MVMCoreErrorObject alloc] initWithTitle:title messageToLog:message code:code domain:domain location:[self errorLocationForRequest:loadObject]]]; +} + +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(MVMCoreLoadObject *)loadObject causedBy:(NSError *)error { + return [self attachLoadInformation:loadObject toError:[MVMCoreErrorObject createErrorObjectForNSError:error location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]]; +} + +- (nonnull MVMCoreErrorObject *)attachLoadInformation:(MVMCoreLoadObject *)loadObject toError:(MVMCoreErrorObject *)error { + return error; // For now, just exposed for overriding. +} + - (nonnull NSString *)errorLocationForRequest:(nonnull MVMCoreLoadObject *)loadObject { - - return [self errorLocationForRequest:loadObject.delegateObject.loadDelegate pageType:loadObject.requestParameters.pageType modules:[NSString stringWithFormat:@"%@",loadObject.requestParameters.modules]]; + return [self errorLocationForRequest:loadObject.delegateObject.loadDelegate + pageType:loadObject.requestParameters.pageType + modules:[NSString stringWithFormat:@"%@", loadObject.requestParameters.modules]]; } - (nonnull NSString *)errorLocationForRequest:(nonnull id)requestingObject pageType:(nonnull NSString *)pageType modules:(nonnull NSString *)modules { @@ -349,7 +362,7 @@ if (!jsonObject) { // Error serializing json. - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] messageToLog:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:locationForError]; + errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] messageToLog:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] code:ErrorCodeParsingJSON domain:ErrorDomainSystem location:locationForError]; } else { // Uncomment to get the raw UTF-8 string response from server before it is parsed. Useful for identifying issues such as duplicate definitions which are removed after parsing. (Also, be careful of parsing tools such as jsoneditoronline.org which will autoresolve some of these issues as well.) @@ -362,7 +375,7 @@ } } else { // Empty response. - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeEmptyResponse domain:ErrorDomainNative location:locationForError]; + errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeEmptyResponse domain:ErrorDomainSystem location:locationForError]; } } else if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(createErrorObjectForRequestNSError:forRequest:location:)]) { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h index 1a9f80a..0afd035 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h @@ -22,6 +22,7 @@ @property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject; @property (nullable, strong, nonatomic) NSDictionary *dataForPage; @property (nullable, strong, nonatomic) DelegateObject *delegateObject; +@property (nullable, nonatomic, readonly) NSURLSessionTask *sessionTask; @property (nullable, nonatomic, readonly) NSString *finalLoadSource; @property (nonatomic) BOOL backgroundLoad; @property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 48f104c..848d283 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -291,7 +291,7 @@ } else { // Error json not correct format. - MVMCoreErrorObject *errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + MVMCoreErrorObject *errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainSystem]; [MVMCoreLoadRequestOperation loadAbortedWithError:errorObject loadObject:loadObject]; } } else { @@ -498,6 +498,7 @@ if (error.errorScreenError && !error.nativeDrivenErrorScreen && loadObject.pageType.length == 0) { error.logError = YES; error.errorScreenError = NO; + error.silentError = NO; error.location = [NSString stringWithFormat:@"%li-%@",(long)ErrorCodeNoErrorPageSent,error.location]; [MVMCoreLoadRequestOperation handleError:error loadObject:loadObject showAlertForErrorIfApplicable:YES]; [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:error]; @@ -571,7 +572,8 @@ } else if ([ValueTypeErrorScreen isEqualToString:type]) { // Error Screen, abort the load and handle the screen if necessary - MVMCoreErrorObject *error = [MVMCoreErrorObject createErrorObjectForErrorInfo:loadObject.responseInfoMap location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + MVMCoreErrorObject *error = [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError:[MVMCoreErrorObject createErrorObjectForErrorInfo:loadObject.responseInfoMap location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]]; + [MVMCoreLoadRequestOperation loadAbortedWithError:error loadObject:loadObject]; } else { @@ -582,7 +584,7 @@ } else { // Check for controller specific errors. BOOL shouldContinue; - MVMCoreErrorObject *error = [MVMCoreErrorObject createErrorObjectForErrorInfo:loadObject.responseInfoMap location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + MVMCoreErrorObject *error = [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError:[MVMCoreErrorObject createErrorObjectForErrorInfo:loadObject.responseInfoMap location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]]; if ([loadObject.delegateObject.loadDelegate respondsToSelector:@selector(checkForDelegateSpecificErrors:loadObject:completionHandler:)]) { shouldContinue = [loadObject.delegateObject.loadDelegate checkForDelegateSpecificErrors:error loadObject:loadObject completionHandler:completionHandler]; } else { @@ -614,16 +616,22 @@ } if (obj && [obj isKindOfClass:[NSDictionary class]]) { - NSDictionary *responseInfo = [obj dict:KeyResponseInfo]; if (![ValueTypeSuccess isEqualToString:[responseInfo string:KeyType]]) { - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[responseInfo stringForKey:KeyErrorHeading] message:[responseInfo stringForKey:KeyUserMessage] messageToLog:[responseInfo stringForKey:KeyMessage] code:[[responseInfo string:KeyCode] integerValue] domain:ErrorDomainServer location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + errorObject = [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError: + [[MVMCoreErrorObject alloc] + initWithTitle:[responseInfo stringForKey:KeyErrorHeading] + message:[responseInfo stringForKey:KeyUserMessage] + messageToLog:[responseInfo stringForKey:KeyMessage] + code:[[responseInfo string:KeyCode] integerValue] + domain:ErrorDomainServer + location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]]; } // Caches each dictionary from the array. [[MVMCoreCache sharedCache] addModuleToCache:obj module:key queue:nil waitUntilFinished:YES completionBlock:NULL]; } else { - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainSystem]; } if (errorObject) { @@ -666,10 +674,10 @@ if (pageType) { [[MVMCoreCache sharedCache] addPageToCache:obj pageType:pageType queue:nil waitUntilFinished:YES completionBlock:NULL]; } else { - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeNoPageType domain:ErrorDomainNative]; } } else { - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainNative]; } // Logs the error. @@ -713,7 +721,7 @@ } } else { // Couldn't initialize view controller, serious error. - error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeInitViewController domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + error = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeInitViewController domain:ErrorDomainNative]; } [MVMCoreLoadRequestOperation handleShouldContinue:shouldContinue error:error loadObject:loadObject errorBlock:NULL continueBlock:^{ diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h index 86fdda0..b91326e 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h @@ -22,6 +22,11 @@ @property (nullable, strong, nonatomic) NSString *systemDomain; @property (nonatomic) NSInteger code; @property (nonatomic) UIApplicationState applicationState; +@property (nullable, strong, nonatomic) NSString *sessionId; +@property (nullable, strong, nonatomic) NSString *requestId; +@property (nullable, strong, nonatomic) NSString *requestUrl; +@property (nonatomic, assign) NSInteger httpStatusCode; +@property (nonatomic, strong) NSDictionary *serverResponseInfo; // For the crash log. @property (nullable, strong, nonatomic) NSDictionary *crashLog; diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index 09f76b4..40432d0 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -28,21 +28,17 @@ self.domain = domain; self.location = location; self.date = [NSDate date]; + self.silentError = YES; // TODO: Hold on this. Messes with server errors. + self.logError = YES; [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ self.applicationState = [UIApplication sharedApplication].applicationState; }]; - - // We don't log server errors. - if (![domain isEqualToString:ErrorDomainServer]) { - self.logError = YES; - // Native and system errors have an error screen. - if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { - self.errorScreenError = YES; - self.nativeDrivenErrorScreen = YES; - } - } else { - self.logError = NO; + // Native and system errors have an error screen. + if (![domain isEqualToString:ErrorDomainServer] && [[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { + self.errorScreenError = YES; + self.nativeDrivenErrorScreen = YES; + self.silentError = NO; } } return self; @@ -58,20 +54,17 @@ self.domain = domain; self.location = location; self.date = [NSDate date]; + self.silentError = YES; // TODO: Hold on this. Messes with server errors. + self.logError = YES; [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ self.applicationState = [UIApplication sharedApplication].applicationState; }]; - // We don't log server errors. - if (![domain isEqualToString:ErrorDomainServer]) { - self.logError = YES; - - // Native and system errors have an error screen. - if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { - self.errorScreenError = YES; - self.nativeDrivenErrorScreen = YES; - } - } else { - self.logError = NO; + + // Native and system errors have an error screen. + if (![domain isEqualToString:ErrorDomainServer] && [[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { + self.errorScreenError = YES; + self.nativeDrivenErrorScreen = YES; + self.silentError = NO; } } return self; @@ -91,12 +84,12 @@ NSInteger errorCode = [[errorInfo string:KeyCode] integerValue]; NSString *type = [errorInfo string:KeyType]; if (![ValueTypeSuccess isEqualToString:type]) { - NSString *title = [errorInfo string:KeyErrorHeading] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle]; NSString *message = [errorInfo string:KeyUserMessage] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess]; - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:title message:message messageToLog:[errorInfo string:KeyMessage] code:errorCode domain:ErrorDomainServer location:location]; + MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:title message:message messageToLog:[errorInfo string:KeyMessage] ?: @"ResponseInfo type is not Success." code:errorCode domain:ErrorDomainServer location:location]; + error.silentError = NO; + error.serverResponseInfo = errorInfo; if ([ValueTypeErrorScreen isEqualToString:type]) { - // If this is a server error screen, there should be no additional alerts... It will be handled by the load handler. error.errorScreenError = YES; } From a74aa6ef2dd882b3b9b7f2a5daebc682e8bd8788 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 27 Feb 2023 14:17:01 -0500 Subject: [PATCH 31/68] Shift logging load errors until after background handling is resolved. --- .../LoadHandling/MVMCoreLoadRequestOperation.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 848d283..e48c6dc 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -439,6 +439,8 @@ NSString *messageStyle = [loadObject.responseInfoMap string:KeyMessageStyle]; if (messageStyle && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest)) { loadObject.operation.alertToShow = YES; + } else { + error.silentError = YES; } } @@ -750,17 +752,19 @@ return; } - // Logs the error. - if (error.logError) { - [MVMCoreLoggingHandler addErrorToLog:error]; - } - MVMCoreLog(@"Error: %@ %@ %@ %@ %@",[error stringErrorCode], error.domain, error.location,error.messageToDisplay, error.messageToLog); if (showAlertForErrorIfApplicable && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest) && !loadObject.requestParameters.handleErrorsSilently && !error.silentError && !error.errorScreenError) { // Show alert for error. [MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:error delegateObject:loadObject.operation.delegateObject]; + } else { + error.silentError = YES; + } + + // Logs the error. + if (error.logError) { + [MVMCoreLoggingHandler addErrorToLog:error]; } } From 52883a534b97198914169dc8f50e155669c33ba8 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 28 Feb 2023 22:08:40 -0500 Subject: [PATCH 32/68] Create MFPerformanceErrorObject for error logging. --- MVMCore/MVMCore/Constants/MVMCoreErrorConstants.h | 3 ++- MVMCore/MVMCore/Utility/MVMCoreErrorObject.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.h b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.h index de916ed..ef1115d 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.h @@ -40,5 +40,6 @@ typedef NS_ENUM(NSInteger, ErrorCode) { ErrorCodeSSL,//23 ErrorCodeNoViewControllerToPresentOn,//24 ErrorCodeNoErrorPageSent, //25 - ErrorCodeFontNotFound //26 + ErrorCodeFontNotFound, //26 + ErrorCodePoorPerformance //27 }; diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h index b91326e..465dc44 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h @@ -26,7 +26,7 @@ @property (nullable, strong, nonatomic) NSString *requestId; @property (nullable, strong, nonatomic) NSString *requestUrl; @property (nonatomic, assign) NSInteger httpStatusCode; -@property (nonatomic, strong) NSDictionary *serverResponseInfo; +@property (nullable, strong, nonatomic) NSDictionary *serverResponseInfo; // For the crash log. @property (nullable, strong, nonatomic) NSDictionary *crashLog; From 56857f187b385ce4dbb566de8123cf2328a75b6b Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Thu, 2 Mar 2023 20:26:48 -0500 Subject: [PATCH 33/68] Silence most errors. Push getNativeScreenForRequestError to LoadHandler decoration. Native error screen error message handling. --- .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 8 ++++++- .../MVMCoreLoadRequestOperation.m | 14 +++++++---- MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 24 +++---------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index e5eb99d..8058ca5 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -104,7 +104,13 @@ } - (nonnull MVMCoreErrorObject *)attachLoadInformation:(MVMCoreLoadObject *)loadObject toError:(MVMCoreErrorObject *)error { - return error; // For now, just exposed for overriding. + // Native and system errors have an error screen. + if (![error.domain isEqualToString:ErrorDomainServer] && [[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { + error.errorScreenError = YES; + error.nativeDrivenErrorScreen = YES; + error.silentError = NO; + } + return error; } - (nonnull NSString *)errorLocationForRequest:(nonnull MVMCoreLoadObject *)loadObject { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index e48c6dc..680ce37 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -297,6 +297,7 @@ } else { // Error with the request/response + [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError:error]; [MVMCoreLoadRequestOperation loadAbortedWithError:error loadObject:loadObject]; } }]; @@ -521,8 +522,12 @@ // Display or finish if (error.errorScreenError || !loadObject.requestParameters.dontDisplayViewController) { + error.silentError = NO; + [MVMCoreLoggingHandler addErrorToLog:error]; [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else { + error.silentError = YES; + [MVMCoreLoggingHandler addErrorToLog:error]; [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:viewController errorObject:error]; } } else if (!loadObject.requestParameters.shouldNotGoToServerOnCacheFail && (loadObject.pageDataFromCache || loadObject.moduleDataFromCache)) { @@ -534,7 +539,8 @@ loadObject.operation.errorForAlertToShow = nil; [loadObject.operation main]; } else { - + error.silentError = YES; + [MVMCoreLoggingHandler addErrorToLog:error]; // Otherwise the request is finished. [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:error]; } @@ -759,11 +765,11 @@ // Show alert for error. [MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:error delegateObject:loadObject.operation.delegateObject]; } else { - error.silentError = YES; + error.silentError = !error.errorScreenError && !error.nativeDrivenErrorScreen; } - // Logs the error. - if (error.logError) { + // Logs the error. If its a native driven error screen postpone until the native screen is define with its messaging. + if (error.logError && !error.nativeDrivenErrorScreen) { [MVMCoreLoggingHandler addErrorToLog:error]; } } diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index 40432d0..2199023 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -28,18 +28,11 @@ self.domain = domain; self.location = location; self.date = [NSDate date]; - self.silentError = YES; // TODO: Hold on this. Messes with server errors. + self.silentError = YES; self.logError = YES; [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ self.applicationState = [UIApplication sharedApplication].applicationState; }]; - - // Native and system errors have an error screen. - if (![domain isEqualToString:ErrorDomainServer] && [[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { - self.errorScreenError = YES; - self.nativeDrivenErrorScreen = YES; - self.silentError = NO; - } } return self; } @@ -54,18 +47,11 @@ self.domain = domain; self.location = location; self.date = [NSDate date]; - self.silentError = YES; // TODO: Hold on this. Messes with server errors. + self.silentError = YES; self.logError = YES; [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ self.applicationState = [UIApplication sharedApplication].applicationState; }]; - - // Native and system errors have an error screen. - if (![domain isEqualToString:ErrorDomainServer] && [[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { - self.errorScreenError = YES; - self.nativeDrivenErrorScreen = YES; - self.silentError = NO; - } } return self; } @@ -104,13 +90,9 @@ if (errorObject) { return errorObject; } - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] messageToLog:[error description] code:[error code] domain:ErrorDomainSystem location:location]; + errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] messageToLog:[error localizedFailureReason] ?: [error localizedDescription] code:[error code] domain:ErrorDomainSystem location:location]; if ([error.domain isEqualToString:NSURLErrorDomain]) { errorObject.systemDomain = error.domain; - if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(getNativeScreenForRequestError:requestObject:)]) { - errorObject.errorScreenError = YES; - errorObject.nativeDrivenErrorScreen = YES; - } } return errorObject; } From 3b85ca1ff8aa57449852c7016290106bd79e080c Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 3 Mar 2023 19:24:33 -0500 Subject: [PATCH 34/68] Track web view navigation failures (timeouts, etc). --- MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index 2199023..a480f9c 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -91,9 +91,10 @@ return errorObject; } errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] messageToLog:[error localizedFailureReason] ?: [error localizedDescription] code:[error code] domain:ErrorDomainSystem location:location]; - if ([error.domain isEqualToString:NSURLErrorDomain]) { + if ([error.domain isEqualToString:NSURLErrorDomain] || [error.domain isEqualToString:@"WebKitErrorDomain"]) { errorObject.systemDomain = error.domain; } + errorObject.requestUrl = error.userInfo[NSURLErrorFailingURLStringErrorKey]; return errorObject; } From 7a38ecf62b743018b6225f62de87bb8a53d49d78 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 6 Mar 2023 15:58:33 -0500 Subject: [PATCH 35/68] Crash fix for missing UserMessage. Suppress alertToShow dialogs when a native error screen is present. Pipe template parsing description messages to error object. Provide a messageToLog for invalid openURL calls. --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h | 1 + MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m | 5 +++++ .../MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 3 ++- MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h index 93e7404..775bd55 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.h @@ -35,6 +35,7 @@ // Returns an error given a load object and error details. Attaches session data related to the load. Important for proper logging. - (nonnull MVMCoreErrorObject *)errorForLoadObject:(nonnull MVMCoreLoadObject *)loadObject withTitle:(nullable NSString *)title message:(nullable NSString *)message code:(NSInteger)code domain:(nonnull NSString *)domain; +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(nonnull MVMCoreLoadObject *)loadObject withTitle:(nullable NSString *)title message:(nullable NSString *)message messageToLog:(nullable NSString *)messageToLog code:(NSInteger)code domain:(nonnull NSString *)domain; // Returns an error given a load object and NSError. Attaches session data related to the load. Important for proper logging. - (nonnull MVMCoreErrorObject *)errorForLoadObject:(nonnull MVMCoreLoadObject *)loadObject causedBy:(nonnull NSError *)error; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 8058ca5..a5f65c1 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -99,6 +99,10 @@ return [self attachLoadInformation:loadObject toError:[[MVMCoreErrorObject alloc] initWithTitle:title messageToLog:message code:code domain:domain location:[self errorLocationForRequest:loadObject]]]; } +- (nonnull MVMCoreErrorObject *)errorForLoadObject:(MVMCoreLoadObject *)loadObject withTitle:(NSString *)title message:(NSString *)message messageToLog:(NSString *)messageToLog code:(NSInteger)code domain:(NSString *)domain { + return [self attachLoadInformation:loadObject toError:[[MVMCoreErrorObject alloc] initWithTitle:title message:message messageToLog:messageToLog code:code domain:domain location:[self errorLocationForRequest:loadObject]]]; +} + - (nonnull MVMCoreErrorObject *)errorForLoadObject:(MVMCoreLoadObject *)loadObject causedBy:(NSError *)error { return [self attachLoadInformation:loadObject toError:[MVMCoreErrorObject createErrorObjectForNSError:error location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]]; } @@ -109,6 +113,7 @@ error.errorScreenError = YES; error.nativeDrivenErrorScreen = YES; error.silentError = NO; + error.messageToDisplay = error.messageToDisplay ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess]; } return error; } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 680ce37..fb6bb64 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -523,10 +523,11 @@ // Display or finish if (error.errorScreenError || !loadObject.requestParameters.dontDisplayViewController) { error.silentError = NO; + loadObject.operation.alertToShow = NO; + loadObject.operation.errorForAlertToShow = nil; [MVMCoreLoggingHandler addErrorToLog:error]; [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else { - error.silentError = YES; [MVMCoreLoggingHandler addErrorToLog:error]; [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:viewController errorObject:error]; } diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index a480f9c..f6c53bb 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -90,7 +90,13 @@ if (errorObject) { return errorObject; } - errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] messageToLog:[error localizedFailureReason] ?: [error localizedDescription] code:[error code] domain:ErrorDomainSystem location:location]; + errorObject = [[MVMCoreErrorObject alloc] + initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] + message:[error localizedDescription] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] + messageToLog:[error localizedFailureReason] ?: [error localizedDescription] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] + code:[error code] + domain:ErrorDomainSystem + location:location]; if ([error.domain isEqualToString:NSURLErrorDomain] || [error.domain isEqualToString:@"WebKitErrorDomain"]) { errorObject.systemDomain = error.domain; } From cb401ee3f082103fb1d4a8fb7ec608da2fca3766 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 6 Mar 2023 17:43:06 -0500 Subject: [PATCH 36/68] Fix prior commit. Allow error alerts if there isn't a full screen error. --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index fb6bb64..5ff0ea8 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -523,8 +523,10 @@ // Display or finish if (error.errorScreenError || !loadObject.requestParameters.dontDisplayViewController) { error.silentError = NO; - loadObject.operation.alertToShow = NO; - loadObject.operation.errorForAlertToShow = nil; + if (error.errorScreenError || error.nativeDrivenErrorScreen) { // Suppress alert errors if there is a full screen error. + loadObject.operation.alertToShow = NO; + loadObject.operation.errorForAlertToShow = nil; + } [MVMCoreLoggingHandler addErrorToLog:error]; [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else { From 85ebbdf44cd0a44e6f8d646adba1c17fa2468023 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 13 Mar 2023 15:49:12 -0400 Subject: [PATCH 37/68] code review catches --- MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m index e9028ff..20be6b4 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreErrorConstants.m @@ -10,9 +10,9 @@ // Error Domains -/// Communication breakddowns. +/// Communication breakdowns. NSString * const ErrorDomainSystem = @"ErrorDomainSystem"; -/// Any sort of native error not due to server directivees. +/// Any sort of native error not due to server directives. NSString * const ErrorDomainNative = @"ErrorDomainNative"; /// Specific errors defined by the server. NSString * const ErrorDomainServer = @"ErrorDomainServer"; From 4799c3fcbba9a79d1e468f7172fa6d0de651ab2e Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 13 Mar 2023 16:13:44 -0400 Subject: [PATCH 38/68] Add image loading failures to error log. --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index c402552..4c121bf 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -592,6 +592,10 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; //system stores cache based datatask and check cache based on response, //need to manually store cache for response [sharedCache storeCachedResponse:cachedReponse forRequest:request]; + } else if (error) { + [MVMCoreLoggingHandler addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreCache->downloadImage"]]; + } else { + [MVMCoreLoggingHandler addErrorToLog:[[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[NSString stringWithFormat:@"Failed to download image %@", request.URL.absoluteString] code:0 domain:ErrorDomainSystem location:@"MVMCoreCache->downloadImage"]]; } if (isGif) { [self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler]; From ab0c13efaf6fd4c63028ae2d67a0a4eb0fcdf726 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Mon, 13 Mar 2023 19:45:58 -0400 Subject: [PATCH 39/68] Prevent double logging and double error popup. --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index 0e751a7..5975af9 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -132,6 +132,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { @objc open func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable: Any]?) { guard error.logError else { return } MVMCoreLoggingHandler.addError(toLog: error) + error.logError = false // Further attempts to log the same error will be skipped. (Legacy action flow.) } // MARK: - Legacy Holdovers From a07807e6937bf91c3fa267f5c924c4dc2439ff30 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 15 Mar 2023 09:04:58 -0400 Subject: [PATCH 40/68] code review --- .../LoadHandling/MVMCoreLoadRequestOperation.m | 12 +++++------- MVMCore/MVMCore/Utility/MVMCoreErrorObject.m | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 5ff0ea8..72659e2 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -440,8 +440,6 @@ NSString *messageStyle = [loadObject.responseInfoMap string:KeyMessageStyle]; if (messageStyle && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest)) { loadObject.operation.alertToShow = YES; - } else { - error.silentError = YES; } } @@ -521,13 +519,13 @@ if (viewController) { // Display or finish - if (error.errorScreenError || !loadObject.requestParameters.dontDisplayViewController) { + if (error.errorScreenError) { error.silentError = NO; - if (error.errorScreenError || error.nativeDrivenErrorScreen) { // Suppress alert errors if there is a full screen error. - loadObject.operation.alertToShow = NO; - loadObject.operation.errorForAlertToShow = nil; + if (error.nativeDrivenErrorScreen) { + [MVMCoreLoggingHandler addErrorToLog:error]; } - [MVMCoreLoggingHandler addErrorToLog:error]; + [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; + } else if (!loadObject.requestParameters.dontDisplayViewController) { [MVMCoreLoadRequestOperation displayViewController:viewController loadObject:loadObject error:error]; } else { [MVMCoreLoggingHandler addErrorToLog:error]; diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m index f6c53bb..9b316dd 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.m @@ -93,7 +93,7 @@ errorObject = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[error localizedDescription] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] - messageToLog:[error localizedFailureReason] ?: [error localizedDescription] ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] + messageToLog:[error description] code:[error code] domain:ErrorDomainSystem location:location]; From 8ab96097249ce8906cc5129f6d44f867057956f1 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 15 Mar 2023 13:28:29 -0400 Subject: [PATCH 41/68] code review. remove silentError hard set. --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 72659e2..ee714c3 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -540,7 +540,6 @@ loadObject.operation.errorForAlertToShow = nil; [loadObject.operation main]; } else { - error.silentError = YES; [MVMCoreLoggingHandler addErrorToLog:error]; // Otherwise the request is finished. [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:error]; From 40741deac35a67b48071a55174461982bc921c55 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 10 Apr 2023 11:50:42 -0400 Subject: [PATCH 42/68] setup biometrics action --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 4 ++++ MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index ee714c3..a75cdb5 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -357,6 +357,10 @@ return; } + if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(modifyJSON:)]) { + jsonDictionary = [[MVMCoreObject sharedInstance].globalLoadDelegate modifyJSON:jsonDictionary]; + } + loadObject.responseJSON = jsonDictionary; // Store the new page data if we didn't load page data from the cache. diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h index 65ea153..bd2c82d 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h @@ -16,6 +16,8 @@ @optional +- (nonnull NSDictionary *)modifyJSON:(nonnull NSDictionary *)json; + // Provides the desired error screen for the native error. Called on the main thread. If set, any native errors or NSURLErrorDomain errors will use a native screen. - (nullable UIViewController *)getNativeScreenForRequestError:(nonnull MVMCoreErrorObject *)errorObject requestObject:(nonnull MVMCoreRequestParameters *)requestObject; From 11d635fdd40d39f6e807bf349fceae4ae1c0aa22 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Mon, 10 Apr 2023 23:34:48 +0530 Subject: [PATCH 43/68] added pageload tracking event --- .../ActionOpenPageHandler.swift | 6 ++- .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 1 + .../MVMCore/LoadHandling/MVMCoreLoadObject.h | 3 ++ .../MVMCoreLoadRequestOperation.h | 1 + .../MVMCoreLoadRequestOperation.m | 22 ++++++-- .../MVMCore/OtherHandlers/MVMCoreEvent.swift | 54 ++++++++++++++++++- MVMCore/MVMCore/Utility/MVMCoreErrorObject.h | 3 ++ 7 files changed, 85 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 0267ea4..2a1c4e6 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -43,6 +43,10 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { /// Adds client parameters and makes calls performRequest() open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { + let coreLoadRequestOperation = MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) + if let pageType = requestParameters.pageType, let identifier = coreLoadRequestOperation?.identifier { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: identifier)) + } // Adds any client parameters to the request parameters. if let parametersToFetch = model.clientParameters, let fetchedParameters = try await ClientParameterHandler().getClientParameters( @@ -53,7 +57,7 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { requestParameters.add(fetchedParameters) } try Task.checkCancellation() - return MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) + return coreLoadRequestOperation } /// Ensures background requests do not have showing errors. diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index a5f65c1..4430e4b 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -114,6 +114,7 @@ error.nativeDrivenErrorScreen = YES; error.silentError = NO; error.messageToDisplay = error.messageToDisplay ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess]; + error.identifier = loadObject.identifier; } return error; } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h index 1ee321d..13cf571 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h @@ -58,6 +58,9 @@ // The full response json @property (nullable, strong, nonatomic) NSDictionary *responseJSON; +//Unique Identifier for event tracking +@property (nonatomic, nonatomic, nonnull) NSString *identifier; + - (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject; - (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h index 0afd035..b441019 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h @@ -26,6 +26,7 @@ @property (nullable, nonatomic, readonly) NSString *finalLoadSource; @property (nonatomic) BOOL backgroundLoad; @property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded; +@property (nonnull, nonatomic, readonly) NSString *identifier; /// Legacy flag for if this operation will have an alert to show when finished. @property (nonatomic, readonly) BOOL alertToShow; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index ee714c3..18f9b2c 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -35,6 +35,7 @@ // For temporarily storing any alert to show until we determine it's delegate. @property (nonatomic, readwrite) BOOL alertToShow; @property (strong, nonatomic, nullable) MVMCoreErrorObject *errorForAlertToShow; +@property (nullable, nonatomic, readwrite) NSString *identifier; @end @@ -48,6 +49,7 @@ self.dataForPage = dataForPage; self.delegateObject = delegateObject; self.backgroundLoad = backgroundLoad; + self.identifier = [NSUUID UUID].UUIDString; } return self; } @@ -55,6 +57,7 @@ - (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad { if (self = [self initWithRequestParameters:loadObject.requestParameters dataForPage:loadObject.dataForPage delegateObject:loadObject.delegateObject backgroundLoad:backgroundLoad]) { + loadObject.identifier = self.identifier; self.loadObject = loadObject; } return self; @@ -120,6 +123,7 @@ // No load requested, finish. MVMCoreLoadObject *loadObject = [[MVMCoreLoadObject alloc] initWithRequestParameters:nil dataForPage:self.dataForPage delegateObject:self.delegateObject]; + loadObject.identifier = self.identifier; loadObject.operation = self; [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:nil]; } else if (self.loadObject) { @@ -155,9 +159,19 @@ [MVMCoreLoadRequestOperation handleLoadObject:loadObject error:nil]; } else { + if(loadObject.requestParameters.pageType) { + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadStartedFor:loadObject.requestParameters.pageType requestUUID:loadObject.identifier requestURL:@"requestURL"]; + } + // Send a new request to the server. [MVMCoreLoadRequestOperation sendRequest:requestForMissingData loadObject:loadObject completionHandler:^(NSDictionary * _Nullable json) { - + + NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; + + if(loadObject.requestParameters.pageType && serverProcessTime) { + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:@"requestURL" requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + } + // Process the data retrieved from the server. [MVMCoreLoadRequestOperation processJSONFromServer:json loadObject:loadObject completionHandler:^(MVMCoreLoadObject * _Nonnull loadObject, MVMCoreErrorObject * _Nullable error) { @@ -226,7 +240,7 @@ if (pageFromCache) { loadObject.pageType = self.requestParameters.pageType; } - + loadObject.identifier = self.identifier; // Store if we loaded from the cache or not. loadObject.pageDataFromCache = (pageFromCache != nil); loadObject.moduleDataFromCache = (modulesFromCache != nil); @@ -292,10 +306,11 @@ // Error json not correct format. MVMCoreErrorObject *errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainSystem]; + errorObject.identifier = loadObject.identifier; [MVMCoreLoadRequestOperation loadAbortedWithError:errorObject loadObject:loadObject]; } } else { - + error.identifier = loadObject.identifier; // Error with the request/response [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError:error]; [MVMCoreLoadRequestOperation loadAbortedWithError:error loadObject:loadObject]; @@ -748,6 +763,7 @@ // Once displyed, we are finished. [MVMCoreActionUtility displayViewController:viewController forLoadObject:loadObject presentationDelegate:loadObject.operation completionHandler:^{ + NSLog(@"screen appear from displayViewController"); [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:viewController errorObject:error]; }]; } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 73d8ecc..5adb3fa 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -82,9 +82,42 @@ public enum MVMCoreEvent { actionId: String ) + case pageStarted( + pageType: String, + requestUUID: String + ) + + case pageLoadStarted( + pageType: String, + requestUUID: String, + requestURL: String + ) + + case pageLoadComplete( + pageType: String, + requestUUID: String, + serverProcessingTime: String, + requestURL: String, + isFromCache: Bool + ) + + case pageProcessingComplete( + pageType: String, + requestUUID: String, + webUrl: String? + ) + + case pageRenderComplete( + pageType: String, + requestUUID: String, + templateName: String?, + controllerName: String + ) + public enum EventType: String { case action case clientParameter + case pageLoad public var notification: Notification.Name { return Notification.Name(rawValue: rawValue) @@ -102,6 +135,7 @@ public enum MVMCoreEvent { case .clientParameterStartFetch: return .clientParameter case .clientParameterTimeout: return .clientParameter case .clientParameterFetchComplete: return .clientParameter + case .pageStarted, .pageLoadStarted, .pageLoadComplete, .pageProcessingComplete, .pageRenderComplete: return .pageLoad } } @@ -123,5 +157,23 @@ extension MVMCoreLoggingHandler { func logCoreEvent(_ event: MVMCoreEvent, at timestamp: Int64 = Date.unixMillisecondsNow()) { recordEvent(event.type.rawValue, attributes: ["timestamp": timestamp, "event": event]) } - +} + +@objc public extension MVMCoreLoggingHandler { + + @objc func logPageLoadStarted(for pageType: String, requestUUID: String, requestURL: String) { + logCoreEvent(.pageLoadStarted(pageType: pageType, requestUUID: requestUUID, requestURL: requestURL)) + } + + @objc func logPageLoadComplete(for pageType: String, serverProcessingTime: String, requestURL: String, requestUUID: String, isFromCache: Bool) { + logCoreEvent(.pageLoadComplete(pageType: pageType, requestUUID: requestUUID, serverProcessingTime: serverProcessingTime, requestURL: requestURL, isFromCache: isFromCache)) + } + + @objc func logPageProcessingComplete(for pageType: String, requestUUID: String, webUrl: String?) { + logCoreEvent(.pageProcessingComplete(pageType: pageType, requestUUID: requestUUID, webUrl: webUrl)) + } + + @objc func logPageRenderComplete(for pageType: String, requestUUID: String, templateName: String?, controllerName: String) { + logCoreEvent(.pageRenderComplete(pageType: pageType, requestUUID: requestUUID, templateName: templateName, controllerName: controllerName)) + } } diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h index 465dc44..c717855 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h @@ -28,6 +28,9 @@ @property (nonatomic, assign) NSInteger httpStatusCode; @property (nullable, strong, nonatomic) NSDictionary *serverResponseInfo; +//Unique Identifier for event tracking +@property (nonatomic, nonatomic, nonnull) NSString *identifier; + // For the crash log. @property (nullable, strong, nonatomic) NSDictionary *crashLog; From f93e1866c13d689a40dcf6e2f4e58a8e2500604d Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 11 Apr 2023 18:28:25 +0530 Subject: [PATCH 44/68] added error msg in pagerender --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 1 - MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 18f9b2c..bf8e69a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -763,7 +763,6 @@ // Once displyed, we are finished. [MVMCoreActionUtility displayViewController:viewController forLoadObject:loadObject presentationDelegate:loadObject.operation completionHandler:^{ - NSLog(@"screen appear from displayViewController"); [MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:viewController errorObject:error]; }]; } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 5adb3fa..bbcb6cf 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -111,7 +111,8 @@ public enum MVMCoreEvent { pageType: String, requestUUID: String, templateName: String?, - controllerName: String + controllerName: String, + error: String? ) public enum EventType: String { @@ -173,7 +174,7 @@ extension MVMCoreLoggingHandler { logCoreEvent(.pageProcessingComplete(pageType: pageType, requestUUID: requestUUID, webUrl: webUrl)) } - @objc func logPageRenderComplete(for pageType: String, requestUUID: String, templateName: String?, controllerName: String) { - logCoreEvent(.pageRenderComplete(pageType: pageType, requestUUID: requestUUID, templateName: templateName, controllerName: controllerName)) + @objc func logPageRenderComplete(for pageType: String, requestUUID: String, templateName: String?, controllerName: String, error: String?) { + logCoreEvent(.pageRenderComplete(pageType: pageType, requestUUID: requestUUID, templateName: templateName, controllerName: controllerName, error: error)) } } From 01b14b02e495814b341d575e3222180fa8106892 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 12 Apr 2023 17:45:40 +0530 Subject: [PATCH 45/68] moved pagestarted event --- .../MVMCore/ActionHandling/ActionOpenPageHandler.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 2a1c4e6..59289a3 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -43,10 +43,6 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { /// Adds client parameters and makes calls performRequest() open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { - let coreLoadRequestOperation = MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) - if let pageType = requestParameters.pageType, let identifier = coreLoadRequestOperation?.identifier { - MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: identifier)) - } // Adds any client parameters to the request parameters. if let parametersToFetch = model.clientParameters, let fetchedParameters = try await ClientParameterHandler().getClientParameters( @@ -57,6 +53,10 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { requestParameters.add(fetchedParameters) } try Task.checkCancellation() + let coreLoadRequestOperation = MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) + if let pageType = requestParameters.pageType, let identifier = coreLoadRequestOperation?.identifier { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: identifier)) + } return coreLoadRequestOperation } From 3c9786b4d6a3be96f2154371fbf45742c60b9174 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 13 Apr 2023 11:54:50 -0400 Subject: [PATCH 46/68] Migrate AlertHandler files to swift. --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 20 ++---- .../ActionHandling/MVMCoreActionHandler.swift | 2 +- .../AlertHandling/MVMCoreAlertController.h | 18 ----- .../AlertHandling/MVMCoreAlertController.m | 49 ------------- MVMCore/MVMCore/MVMCore.h | 1 - .../MVMCoreLoggingDelegateProtocol.h | 4 -- .../OtherHandlers/MVMCoreLoggingHandler.h | 2 - .../OtherHandlers/MVMCoreLoggingHandler.m | 6 -- .../MVMCorePresentViewControllerOperation.m | 69 +++---------------- .../MVMCoreActionUtility+Extension.swift | 19 +++++ 10 files changed, 34 insertions(+), 156 deletions(-) delete mode 100644 MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.h delete mode 100644 MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m create mode 100644 MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility+Extension.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 673f872..62ebf04 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -109,6 +109,7 @@ AF7069A02880F0EB00077CF6 /* ActionOpenPageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF70699F2880F0EB00077CF6 /* ActionOpenPageHandler.swift */; }; AF787413286DEF8B00670588 /* ActionBackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF787412286DEF8B00670588 /* ActionBackHandler.swift */; }; AF8D13392774EA1D008AF4A9 /* ActionOpenUrlHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8D13382774EA1D008AF4A9 /* ActionOpenUrlHandler.swift */; }; + AFA4931E29E5C988001A9663 /* MVMCoreActionUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4931D29E5C988001A9663 /* MVMCoreActionUtility+Extension.swift */; }; AFBB96341FBA34310008D868 /* MVMCoreErrorConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96321FBA34310008D868 /* MVMCoreErrorConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = AFBB96331FBA34310008D868 /* MVMCoreErrorConstants.m */; }; AFBB96381FBA39E70008D868 /* MVMCoreLoadDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96371FBA39E70008D868 /* MVMCoreLoadDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -133,8 +134,6 @@ AFBB96951FBA3A9A0008D868 /* MVMCorePresentationDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96771FBA3A9A0008D868 /* MVMCorePresentationDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFBB96961FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96781FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = AFBB96791FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m */; }; - AFBB96981FBA3A9A0008D868 /* MVMCoreAlertController.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB967B1FBA3A9A0008D868 /* MVMCoreAlertController.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = AFBB967C1FBA3A9A0008D868 /* MVMCoreAlertController.m */; }; AFBB96B01FBA3B590008D868 /* MVMCoreDispatchUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96AC1FBA3B590008D868 /* MVMCoreDispatchUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; AFBB96B11FBA3B590008D868 /* MVMCoreDispatchUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = AFBB96AD1FBA3B590008D868 /* MVMCoreDispatchUtility.m */; }; AFBB96B21FBA3B590008D868 /* MVMCoreGetterUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96AE1FBA3B590008D868 /* MVMCoreGetterUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -273,6 +272,7 @@ AF70699F2880F0EB00077CF6 /* ActionOpenPageHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPageHandler.swift; sourceTree = ""; }; AF787412286DEF8B00670588 /* ActionBackHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackHandler.swift; sourceTree = ""; }; AF8D13382774EA1D008AF4A9 /* ActionOpenUrlHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrlHandler.swift; sourceTree = ""; }; + AFA4931D29E5C988001A9663 /* MVMCoreActionUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreActionUtility+Extension.swift"; sourceTree = ""; }; AFBB96321FBA34310008D868 /* MVMCoreErrorConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreErrorConstants.h; sourceTree = ""; }; AFBB96331FBA34310008D868 /* MVMCoreErrorConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreErrorConstants.m; sourceTree = ""; }; AFBB96371FBA39E70008D868 /* MVMCoreLoadDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadDelegateProtocol.h; sourceTree = ""; }; @@ -297,8 +297,6 @@ AFBB96771FBA3A9A0008D868 /* MVMCorePresentationDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCorePresentationDelegateProtocol.h; sourceTree = ""; }; AFBB96781FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCorePresentViewControllerOperation.h; sourceTree = ""; }; AFBB96791FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCorePresentViewControllerOperation.m; sourceTree = ""; }; - AFBB967B1FBA3A9A0008D868 /* MVMCoreAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreAlertController.h; sourceTree = ""; }; - AFBB967C1FBA3A9A0008D868 /* MVMCoreAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreAlertController.m; sourceTree = ""; }; AFBB96AC1FBA3B590008D868 /* MVMCoreDispatchUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreDispatchUtility.h; sourceTree = ""; }; AFBB96AD1FBA3B590008D868 /* MVMCoreDispatchUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreDispatchUtility.m; sourceTree = ""; }; AFBB96AE1FBA3B590008D868 /* MVMCoreGetterUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreGetterUtility.h; sourceTree = ""; }; @@ -391,7 +389,6 @@ 8876D5D41FB50AAB00EB2E3D /* Utility */, AF43A7191FC5BE9E008E9347 /* MainProtocols */, AFBB96B41FBA3CEC0008D868 /* ActionHandling */, - AFBB967A1FBA3A9A0008D868 /* AlertHandling */, AFBB966B1FBA3A9A0008D868 /* PresentationHandling */, AFBB96361FBA39E70008D868 /* LoadHandling */, AFBB96131FBA26650008D868 /* ViewControllerMapping */, @@ -611,15 +608,6 @@ path = PresentationHandling; sourceTree = ""; }; - AFBB967A1FBA3A9A0008D868 /* AlertHandling */ = { - isa = PBXGroup; - children = ( - AFBB967B1FBA3A9A0008D868 /* MVMCoreAlertController.h */, - AFBB967C1FBA3A9A0008D868 /* MVMCoreAlertController.m */, - ); - path = AlertHandling; - sourceTree = ""; - }; AFBB96AB1FBA3B590008D868 /* Helpers */ = { isa = PBXGroup; children = ( @@ -630,6 +618,7 @@ D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */, AF43A5851FBB67D6008E9347 /* MVMCoreActionUtility.h */, AF43A5861FBB67D6008E9347 /* MVMCoreActionUtility.m */, + AFA4931D29E5C988001A9663 /* MVMCoreActionUtility+Extension.swift */, ); path = Helpers; sourceTree = ""; @@ -756,7 +745,6 @@ 8876D5EC1FB50AB000EB2E3D /* NSDictionary+MFConvenience.h in Headers */, AFFCFA651FCCC0D700FD0730 /* MVMCoreLoadingOverlayDelegateProtocol.h in Headers */, AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */, - AFBB96981FBA3A9A0008D868 /* MVMCoreAlertController.h in Headers */, 881D26961FCC9D180079C521 /* MVMCoreOperation.h in Headers */, 8876D5EA1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.h in Headers */, AF43A7201FC5D2BA008E9347 /* MVMCoreViewManagerProtocol.h in Headers */, @@ -905,7 +893,6 @@ BB780ADF250F8C890030BD2F /* ActionNoopModel.swift in Sources */, D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */, 01F2A03623A80A7300D954D8 /* ActionModelProtocol.swift in Sources */, - AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */, 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */, AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */, 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */, @@ -916,6 +903,7 @@ AF43A74D1FC6109F008E9347 /* MVMCoreSessionObject.m in Sources */, D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, + AFA4931E29E5C988001A9663 /* MVMCoreActionUtility+Extension.swift in Sources */, 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index 5975af9..c206300 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -129,7 +129,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { } /// Logs the error. - @objc open func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable: Any]?) { + @objc open func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable: Any]? = nil, delegateObject: DelegateObject? = nil) { guard error.logError else { return } MVMCoreLoggingHandler.addError(toLog: error) error.logError = false // Further attempts to log the same error will be skipped. (Legacy action flow.) diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.h b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.h deleted file mode 100644 index e38bedf..0000000 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// MVMCoreAlertController.h -// alerts -// -// Created by Scott Pfeil on 10/22/14. -// Copyright (c) 2014 Verizon Wireless. All rights reserved. -// -// Used by our alert handler. Not for subclassing. Simply keeps track of if it's visible. Tries to parallel the UIAlertView to make it easier for the MVMCoreAlertHandler. - -#import -@class MVMCoreAlertObject; - -@interface MVMCoreAlertController : UIAlertController - -@property (nonatomic, readonly, getter=isVisible) BOOL visible; -@property (nullable, nonatomic, strong) MVMCoreAlertObject *alertObject; - -@end diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m b/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m deleted file mode 100644 index 11c6fd2..0000000 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreAlertController.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// MVMAlertController.m -// alerts -// -// Created by Scott Pfeil on 10/22/14. -// Copyright (c) 2014 Verizon Wireless. All rights reserved. -// - -#import "MVMCoreAlertController.h" -#import "MVMCoreLoggingHandler.h" -#import "MVMCoreGetterUtility.h" - -@interface MVMCoreAlertController () - -@property (nonatomic, readwrite, getter=isVisible) BOOL visible; - -@end - -@implementation MVMCoreAlertController - -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - - [self willChangeValueForKey:@"isVisible"]; - self.visible = YES; - [self didChangeValueForKey:@"isVisible"]; - [MVMCoreLoggingHandler logAlertForAlertController:self]; -} - -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; - [self willChangeValueForKey:@"isVisible"]; - self.visible = NO; - [self didChangeValueForKey:@"isVisible"]; -} - -- (NSString *)description { - return [NSString stringWithFormat:@"%@|title=%@|message=%@", [super description],self.title,self.message]; -} - -- (UIInterfaceOrientationMask)supportedInterfaceOrientations { - if ([MVMCoreGetterUtility isOnIPad]) { - return UIInterfaceOrientationMaskAll; - } else { - return UIInterfaceOrientationMaskPortrait; - } -} - -@end diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index 8e1a01f..be93c59 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -63,7 +63,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; #import #import #import -#import // Action Handling #import diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h index b8ae254..fc0e353 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreLoggingDelegateProtocol.h @@ -7,7 +7,6 @@ // #import -@class MVMCoreAlertController; @protocol MVMCoreLoggingDelegateProtocol @@ -25,7 +24,4 @@ // Log that the load has finished. - (void)logLoadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController *)loadedViewController error:(nullable MVMCoreErrorObject *)error; -// Log alert -- (void)logAlertForAlertController:(nullable MVMCoreAlertController *)alertController; - @end diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h index d81869f..4cd0b53 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h @@ -11,7 +11,6 @@ #import #import #import -@class MVMCoreAlertController; #define MVMCoreLog(fmt, ...) \ [MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]]; @@ -24,7 +23,6 @@ + (void)logDebugMessageWithDelegate:(nullable NSString *)message; + (void)logWithDelegateWithObject:(nullable id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra; + (void)logWithDelegateLoadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController *)loadedViewController error:(nullable MVMCoreErrorObject *)error; -+ (void)logAlertForAlertController:(nullable MVMCoreAlertController *)alertController; - (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes; #pragma mark MVMCoreLoggingDelegateProtocol diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m index 9765925..4fb541a 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m @@ -45,12 +45,6 @@ } } -+ (void)logAlertForAlertController:(nullable MVMCoreAlertController *)alertController { - if ([[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(logAlertForAlertController:)]) { - [[MVMCoreObject sharedInstance].loggingDelegate logAlertForAlertController:alertController]; - } -} - - (void)recordEvent:(nonnull NSString *)name attributes:(nullable NSDictionary *)attributes {} #pragma mark - logging delegate diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentViewControllerOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentViewControllerOperation.m index 6b7c51b..0e757ab 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentViewControllerOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentViewControllerOperation.m @@ -7,7 +7,6 @@ // #import "MVMCorePresentViewControllerOperation.h" -#import "MVMCoreAlertController.h" #import "MVMCorePresentAnimationOperation.h" #import "MVMCoreDispatchUtility.h" #import "MVMCoreConstants.h" @@ -18,20 +17,10 @@ @property (nullable, strong, nonatomic) UIViewController *presentedViewController; @property (nonatomic) BOOL animate; -@property (nonatomic) BOOL beingObserved; -@property (nullable, weak, nonatomic) MVMCoreAlertController *alertController; - @end @implementation MVMCorePresentViewControllerOperation -// The context for kvo -static void * XXContext = &XXContext; - -- (void)dealloc { - [self stopObservingAlertView]; -} - - (nullable instancetype)initWithPresentingViewController:(nullable UIViewController *)presentingViewController presentedViewController:(nullable UIViewController *)presentedViewController animated:(BOOL)animated { if (self = [super init]) { @@ -67,57 +56,19 @@ static void * XXContext = &XXContext; controllerToPresentOn = controllerToPresentOn.presentedViewController; } - // If an alert is showing, don't present until the alerts are dismissed. - if ([controllerToPresentOn isKindOfClass:[MVMCoreAlertController class]]) { - [self observeForAlertDismissal:(MVMCoreAlertController *)controllerToPresentOn]; - } else { - MVMCorePresentAnimationOperation *animationOperation = [[MVMCorePresentAnimationOperation alloc] initWithPresentingViewController:controllerToPresentOn presentedViewController:self.presentedViewController animated:self.animate]; - animationOperation.delegate = self.delegate; - [animationOperation setCompletionBlock:^{ - [self markAsFinished]; - // Notify that page has changed - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [[NSNotificationCenter defaultCenter] postNotificationName:MVMCoreNotificationViewControllerChanged object:nil]; - }); - }]; - [[NSOperationQueue mainQueue] addOperation:animationOperation]; - } + MVMCorePresentAnimationOperation *animationOperation = [[MVMCorePresentAnimationOperation alloc] initWithPresentingViewController:controllerToPresentOn presentedViewController:self.presentedViewController animated:self.animate]; + animationOperation.delegate = self.delegate; + [animationOperation setCompletionBlock:^{ + [self markAsFinished]; + // Notify that page has changed + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:MVMCoreNotificationViewControllerChanged object:nil]; + }); + }]; + [[NSOperationQueue mainQueue] addOperation:animationOperation]; } else { [self markAsFinished]; } } -- (void)cancel { - [super cancel]; - [self stopObservingAlertView]; -} - -#pragma mark - Observer Functions - -- (void)observeForAlertDismissal:(MVMCoreAlertController *)alertController { - if (!self.beingObserved) { - self.beingObserved = YES; - self.alertController = alertController; - [alertController addObserver:self forKeyPath:@"visible" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:XXContext]; - } -} - -- (void)stopObservingAlertView { - if (self.beingObserved) { - [self.alertController removeObserver:self forKeyPath:@"visible" context:XXContext]; - self.alertController = nil; - self.beingObserved = NO; - } -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - - if (context == XXContext && [keyPath isEqualToString:@"visible"]) { - if (![object isVisible]) { - [self stopObservingAlertView]; - [self present]; - } - } -} - @end diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility+Extension.swift b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility+Extension.swift new file mode 100644 index 0000000..f6b45ce --- /dev/null +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility+Extension.swift @@ -0,0 +1,19 @@ +// +// MVMCoreActionUtility+Extension.swift +// MVMCore +// +// Created by Scott Pfeil on 4/11/23. +// Copyright © 2023 myverizon. All rights reserved. +// + +public extension MVMCoreActionUtility { + static func fatalClassCheck(object: AnyObject?) -> T { + guard let object = object else { + fatalError("Object \(T.self) is nil.") + } + guard let instance = object as? T else { + fatalError("\(object) is not an instance of \(T.self)") + } + return instance + } +} From 15ca6142feeca44721f6b5d0dc438b784483be94 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 17 Apr 2023 13:02:24 -0400 Subject: [PATCH 47/68] Remove reference to AlertObject from core. --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadDelegateProtocol.h | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadDelegateProtocol.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadDelegateProtocol.h index 39ddc8b..db6f5b9 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadDelegateProtocol.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadDelegateProtocol.h @@ -11,7 +11,6 @@ #import @class MVMCoreRequestParameters; @class MVMCoreErrorObject; -@class MVMCoreAlertObject; @class MVMCoreLoadObject; @protocol MVMCoreLoadDelegateProtocol From e3cbc7a7cd06e223598e2f31e4d891b71b4f67d2 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 18 Apr 2023 18:01:43 +0530 Subject: [PATCH 48/68] added backgroundRequest check & addressed reviewcomments --- .../MVMCore/ActionHandling/ActionOpenPageHandler.swift | 8 +++++--- MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h | 2 +- .../MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h | 2 +- .../MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 5 ++--- MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 4 ++++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 59289a3..8e1981f 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -43,6 +43,10 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { /// Adds client parameters and makes calls performRequest() open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { + let actionUUID = MVMCoreActionHandler.getUUID(additionalData: additionalData) ?? UUID().uuidString + if !requestParameters.backgroundRequest, let pageType = requestParameters.pageType { + MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: actionUUID)) + } // Adds any client parameters to the request parameters. if let parametersToFetch = model.clientParameters, let fetchedParameters = try await ClientParameterHandler().getClientParameters( @@ -54,9 +58,7 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { } try Task.checkCancellation() let coreLoadRequestOperation = MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) - if let pageType = requestParameters.pageType, let identifier = coreLoadRequestOperation?.identifier { - MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: identifier)) - } + coreLoadRequestOperation?.identifier = actionUUID return coreLoadRequestOperation } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h index 13cf571..72875fa 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.h @@ -59,7 +59,7 @@ @property (nullable, strong, nonatomic) NSDictionary *responseJSON; //Unique Identifier for event tracking -@property (nonatomic, nonatomic, nonnull) NSString *identifier; +@property (nullable, strong, nonatomic) NSString *identifier; - (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h index b441019..cbf775e 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.h @@ -26,7 +26,7 @@ @property (nullable, nonatomic, readonly) NSString *finalLoadSource; @property (nonatomic) BOOL backgroundLoad; @property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded; -@property (nonnull, nonatomic, readonly) NSString *identifier; +@property (nonnull, nonatomic, strong) NSString *identifier; /// Legacy flag for if this operation will have an alert to show when finished. @property (nonatomic, readonly) BOOL alertToShow; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index bf8e69a..59048a8 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -35,7 +35,6 @@ // For temporarily storing any alert to show until we determine it's delegate. @property (nonatomic, readwrite) BOOL alertToShow; @property (strong, nonatomic, nullable) MVMCoreErrorObject *errorForAlertToShow; -@property (nullable, nonatomic, readwrite) NSString *identifier; @end @@ -159,7 +158,7 @@ [MVMCoreLoadRequestOperation handleLoadObject:loadObject error:nil]; } else { - if(loadObject.requestParameters.pageType) { + if(!loadObject.requestParameters.backgroundRequest && loadObject.requestParameters.pageType) { [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadStartedFor:loadObject.requestParameters.pageType requestUUID:loadObject.identifier requestURL:@"requestURL"]; } @@ -168,7 +167,7 @@ NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; - if(loadObject.requestParameters.pageType && serverProcessTime) { + if(!loadObject.requestParameters.backgroundRequest && loadObject.requestParameters.pageType && serverProcessTime) { [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:@"requestURL" requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index bbcb6cf..3c1d0dd 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -162,6 +162,10 @@ extension MVMCoreLoggingHandler { @objc public extension MVMCoreLoggingHandler { + @objc func pageStarted(for pageType: String, requestUUID: String) { + logCoreEvent(.pageStarted(pageType: pageType, requestUUID: requestUUID)) + } + @objc func logPageLoadStarted(for pageType: String, requestUUID: String, requestURL: String) { logCoreEvent(.pageLoadStarted(pageType: pageType, requestUUID: requestUUID, requestURL: requestURL)) } From 38cb3eb80e16af145eefff094ebcb07eb1cc7005 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Tue, 18 Apr 2023 19:39:45 -0400 Subject: [PATCH 49/68] queue changes --- .../MVMCoreDismissViewControllerOperation.m | 43 ++++++++++--------- .../MVMCoreNavigationHandler.h | 3 -- .../MVMCoreNavigationHandler.m | 15 ++----- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m index 4a09cb4..fbfd950 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m @@ -8,6 +8,7 @@ #import "MVMCoreDismissViewControllerOperation.h" #import "MVMCoreConstants.h" +#import "MVMCoreDispatchUtility.h" typedef NS_ENUM(NSInteger, DismissType) { DismissTypeTop = 0, @@ -49,29 +50,31 @@ typedef NS_ENUM(NSInteger, DismissType) { return; } - switch (self.type) { - case DismissTypeTop: - { - // Gets the top most presented. - UIViewController *controllerToDismiss = self.viewController; - while (controllerToDismiss.presentedViewController) { - controllerToDismiss = controllerToDismiss.presentedViewController; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + switch (self.type) { + case DismissTypeTop: + { + // Gets the top most presented. + UIViewController *controllerToDismiss = self.viewController; + while (controllerToDismiss.presentedViewController) { + controllerToDismiss = controllerToDismiss.presentedViewController; + } + [self dismissViewController:controllerToDismiss]; } - [self dismissViewController:controllerToDismiss]; - } - break; - case DismissTypeSpecific: - { - if (self.viewController.presentingViewController) { - [self dismissViewController:self.viewController.presentingViewController]; - } else { - [self dismissViewController:self.viewController]; + break; + case DismissTypeSpecific: + { + if (self.viewController.presentingViewController) { + [self dismissViewController:self.viewController.presentingViewController]; + } else { + [self dismissViewController:self.viewController]; + } } + break; + default: + break; } - break; - default: - break; - } + }]; } - (void)dismissViewController:(nonnull UIViewController *)viewController { diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h index 86c056d..8548c81 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h @@ -136,9 +136,6 @@ // Use this to dismiss all presented view controllers stacked on the bottom one. - (void)dismissToBottom:(BOOL)animated; -// Removes all queued up items. -- (void)cancelPresentation; - #pragma mark - Presentation Extra // Use this to present. diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m index 15aea59..3f4b2a7 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m @@ -46,9 +46,6 @@ self.navigationQueue = [[NSOperationQueue alloc] init]; self.navigationQueue.maxConcurrentOperationCount = 1; - self.presentationQueue = [[NSOperationQueue alloc] init]; - self.presentationQueue.maxConcurrentOperationCount = 1; - self.delegates = (NSHashTable *)[NSHashTable weakObjectsHashTable]; } return self; @@ -308,10 +305,6 @@ [self dismissToBottom:animated delegate:nil completionHandler:NULL]; } -- (void)cancelPresentation { - [self.presentationQueue cancelAllOperations]; -} - #pragma mark - Presentation Extra - (void)presentViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { @@ -325,7 +318,7 @@ MVMCorePresentViewControllerOperation *operation = [[MVMCorePresentViewControllerOperation alloc] initWithPresentingViewController:controllerToPresentOn presentedViewController:viewController animated:animated]; operation.delegate = delegate; operation.completionBlock = completionBlock; - [self.presentationQueue addOperation:operation]; + [self.navigationQueue addOperation:operation]; } }]; } @@ -336,7 +329,7 @@ UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [MVMCoreGetterUtility getKeyWindow].rootViewController; MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissTopViewController:controllerToPresentOn animated:animated]; operation.completionBlock = completionBlock; - [[NSOperationQueue mainQueue] addOperation:operation]; + [self.navigationQueue addOperation:operation]; }]; } @@ -344,7 +337,7 @@ MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:viewController animated:animated]; operation.completionBlock = completionBlock; - [[NSOperationQueue mainQueue] addOperation:operation]; + [self.navigationQueue addOperation:operation]; } - (void)dismissToBottom:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { @@ -353,7 +346,7 @@ UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [MVMCoreGetterUtility getKeyWindow].rootViewController; MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:controllerToPresentOn animated:animated]; operation.completionBlock = completionBlock; - [[NSOperationQueue mainQueue] addOperation:operation]; + [self.navigationQueue addOperation:operation]; }]; } From f0f842f87edfd77fffb93527098d26423d3df94c Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Wed, 19 Apr 2023 16:36:15 -0400 Subject: [PATCH 50/68] Bug fixes --- .../MVMCore/PresentationHandling/MVMCoreNavigationHandler.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m index 3f4b2a7..a721f50 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m @@ -329,7 +329,7 @@ UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [MVMCoreGetterUtility getKeyWindow].rootViewController; MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissTopViewController:controllerToPresentOn animated:animated]; operation.completionBlock = completionBlock; - [self.navigationQueue addOperation:operation]; + [[NSOperationQueue mainQueue] addOperation:operation]; }]; } @@ -337,7 +337,7 @@ MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:viewController animated:animated]; operation.completionBlock = completionBlock; - [self.navigationQueue addOperation:operation]; + [[NSOperationQueue mainQueue] addOperation:operation]; } - (void)dismissToBottom:(BOOL)animated delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock { @@ -346,7 +346,7 @@ UIViewController *controllerToPresentOn = self.viewControllerToPresentOn ?: [MVMCoreGetterUtility getKeyWindow].rootViewController; MVMCoreDismissViewControllerOperation *operation = [[MVMCoreDismissViewControllerOperation alloc] initAndDismissViewController:controllerToPresentOn animated:animated]; operation.completionBlock = completionBlock; - [self.navigationQueue addOperation:operation]; + [[NSOperationQueue mainQueue] addOperation:operation]; }]; } From bc46ff31740299d9fd11b08e2453eb09424f99eb Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Wed, 19 Apr 2023 16:38:53 -0400 Subject: [PATCH 51/68] revert --- .../MVMCoreDismissViewControllerOperation.m | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m index fbfd950..4a09cb4 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreDismissViewControllerOperation.m @@ -8,7 +8,6 @@ #import "MVMCoreDismissViewControllerOperation.h" #import "MVMCoreConstants.h" -#import "MVMCoreDispatchUtility.h" typedef NS_ENUM(NSInteger, DismissType) { DismissTypeTop = 0, @@ -50,31 +49,29 @@ typedef NS_ENUM(NSInteger, DismissType) { return; } - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - switch (self.type) { - case DismissTypeTop: - { - // Gets the top most presented. - UIViewController *controllerToDismiss = self.viewController; - while (controllerToDismiss.presentedViewController) { - controllerToDismiss = controllerToDismiss.presentedViewController; - } - [self dismissViewController:controllerToDismiss]; + switch (self.type) { + case DismissTypeTop: + { + // Gets the top most presented. + UIViewController *controllerToDismiss = self.viewController; + while (controllerToDismiss.presentedViewController) { + controllerToDismiss = controllerToDismiss.presentedViewController; } - break; - case DismissTypeSpecific: - { - if (self.viewController.presentingViewController) { - [self dismissViewController:self.viewController.presentingViewController]; - } else { - [self dismissViewController:self.viewController]; - } - } - break; - default: - break; + [self dismissViewController:controllerToDismiss]; } - }]; + break; + case DismissTypeSpecific: + { + if (self.viewController.presentingViewController) { + [self dismissViewController:self.viewController.presentingViewController]; + } else { + [self dismissViewController:self.viewController]; + } + } + break; + default: + break; + } } - (void)dismissViewController:(nonnull UIViewController *)viewController { From 14af9f2d5ffa7c659782ab8f6ca9b0d34e98140e Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 19 Apr 2023 20:03:47 -0400 Subject: [PATCH 52/68] Move URL request resolution to MVMCoreRequestParameters. --- .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 26 +-------- .../MVMCoreLoadRequestOperation.m | 2 + .../LoadHandling/MVMCoreRequestParameters.h | 4 ++ .../LoadHandling/MVMCoreRequestParameters.m | 56 +++++++++++++++++++ 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index a5f65c1..d467e08 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -134,31 +134,7 @@ - (nullable NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error { - NSURL *url = requestParameters.URL; - if (!url) { - if (requestParameters.alternateBaseURL) { - url = requestParameters.alternateBaseURL; - } else { - url = [MVMCoreSessionObject sharedGlobal].baseURL ?: [NSURL URLWithString:URLProdPostpayBase]; - } - - // Appends the context root. - if (requestParameters.contextRoot) { - url = [url URLByAppendingPathComponent:requestParameters.contextRoot]; - } else if ([MVMCoreSessionObject sharedGlobal].contextRoot) { - url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; - } - - // Appends the page type - if (requestParameters.pageType) { - url = [url URLByAppendingPathComponent:requestParameters.pageType]; - } - - // This has changed since the initial agreement. Seems server always needs page type now. - /* else if (requestParameters.modules) { - url = [url URLByAppendingPathComponent:KeyModuleMap]; - }*/ - } + NSURL *url = [requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]]; // Adds modules needed to the request parameters. if (requestParameters.modules.count > 0) { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index ee714c3..2c9d340 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -111,6 +111,8 @@ - (void)main { MVMCoreLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegateObject.loadDelegate); + [self.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]]; + // Always check for cancellation before launching the task. if ([self checkAndHandleForCancellation]) { return; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index 2e52a05..a2ca9bf 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -9,6 +9,7 @@ #import #import +#import // The loading style. // MFLoadStyleDefault: This means it has not been explicitely set by the developer. Standard push. @@ -124,4 +125,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { /// Returns optional and required modules - (nullable NSArray *)allModules; +/// Resolves the URL given the session object and the current request parameters. +- (nonnull NSURL *)resolveURL:(nonnull MVMCoreSessionObject *)sessionObject; + @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index e07070a..fb2b083 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -10,15 +10,20 @@ #import "NSDictionary+MFConvenience.h" #import "MVMCoreJSONConstants.h" #import "MVMCoreViewControllerMappingObject.h" +#import "MVMCoreConstants.h" @interface MVMCoreRequestParameters () +@property (nonatomic, strong, nullable) NSURL *determinedURL; + - (nullable instancetype)initWithExtraParameters:(nullable NSDictionary *)extraParameters; @end @implementation MVMCoreRequestParameters +@synthesize URL = _url; + - (nullable instancetype)initWithExtraParameters:(nullable NSDictionary *)extraParameters { if (self = [super init]) { self.parameters = extraParameters; @@ -86,6 +91,56 @@ return self; } +- (void)setAlternateBaseURL:(NSURL *)alternateBaseURL { + _alternateBaseURL = alternateBaseURL; + _url = self.determinedURL; // Reset resolution when changed. +} + +- (void)setPageType:(NSString *)pageType { + _pageType = pageType; + _url = self.determinedURL; // Reset resolution when changed. +} + +- (void)setContextRoot:(NSString *)contextRoot { + _contextRoot = contextRoot; + _url = self.determinedURL; // Reset resolution when changed. +} + +- (void)setURL:(NSURL *)URL { + self.determinedURL = URL; // If set directly, this becomes the ultimate URL. + _url = URL; +} + +- (NSURL *)resolveURL:(MVMCoreSessionObject *)sessionObject { + + if (self.URL) { + // Previously resovled. + return self.URL; + } + + NSURL *url; + if (self.alternateBaseURL) { + url = self.alternateBaseURL; + } else { + url = sessionObject.baseURL ?: [NSURL URLWithString:URLProdPostpayBase]; + } + + // Appends the context root. + if (self.contextRoot) { + url = [url URLByAppendingPathComponent:self.contextRoot]; + } else if (sessionObject.contextRoot) { + url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; + } + + // Appends the page type + if (self.pageType) { + url = [url URLByAppendingPathComponent:self.pageType]; + } + + _url = url; + return url; +} + - (void)addRequestParameters:(nonnull NSDictionary *)parameters { if ([parameters count] > 0) { @@ -152,6 +207,7 @@ copyObject.customTimeoutTime = self.customTimeoutTime; copyObject.backgroundRequest = self.backgroundRequest; copyObject.URL = self.URL; + copyObject.determinedURL = self.determinedURL; copyObject.actionMap = self.actionMap; return copyObject; } From 10db5ff1bab2ac7f67cbdd3c881de74932333efa Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Thu, 20 Apr 2023 16:51:45 +0530 Subject: [PATCH 53/68] addressed review comments --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 59048a8..401eb8b 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -154,11 +154,13 @@ MVMCoreRequestParameters *requestForMissingData = [MVMCoreLoadRequestOperation createRequestForDataWithLoadObject:loadObject]; if (!requestForMissingData) { + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:@"0" requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + // We have all the needed data, continue with the load. [MVMCoreLoadRequestOperation handleLoadObject:loadObject error:nil]; } else { - if(!loadObject.requestParameters.backgroundRequest && loadObject.requestParameters.pageType) { + if(!self.backgroundLoad && loadObject.requestParameters.pageType) { [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadStartedFor:loadObject.requestParameters.pageType requestUUID:loadObject.identifier requestURL:@"requestURL"]; } @@ -167,7 +169,7 @@ NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; - if(!loadObject.requestParameters.backgroundRequest && loadObject.requestParameters.pageType && serverProcessTime) { + if(!self.backgroundLoad && loadObject.requestParameters.pageType && serverProcessTime) { [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:@"requestURL" requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; } From 519093a24f65cf25ebae5997a7078410e01c5f24 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Fri, 21 Apr 2023 13:24:01 -0400 Subject: [PATCH 54/68] remove synthesis --- .../MVMCore/LoadHandling/MVMCoreRequestParameters.m | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index fb2b083..899ef5f 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -22,8 +22,6 @@ @implementation MVMCoreRequestParameters -@synthesize URL = _url; - - (nullable instancetype)initWithExtraParameters:(nullable NSDictionary *)extraParameters { if (self = [super init]) { self.parameters = extraParameters; @@ -93,22 +91,22 @@ - (void)setAlternateBaseURL:(NSURL *)alternateBaseURL { _alternateBaseURL = alternateBaseURL; - _url = self.determinedURL; // Reset resolution when changed. + _URL = self.determinedURL; // Reset resolution when changed. } - (void)setPageType:(NSString *)pageType { _pageType = pageType; - _url = self.determinedURL; // Reset resolution when changed. + _URL = self.determinedURL; // Reset resolution when changed. } - (void)setContextRoot:(NSString *)contextRoot { _contextRoot = contextRoot; - _url = self.determinedURL; // Reset resolution when changed. + _URL = self.determinedURL; // Reset resolution when changed. } - (void)setURL:(NSURL *)URL { self.determinedURL = URL; // If set directly, this becomes the ultimate URL. - _url = URL; + _URL = URL; } - (NSURL *)resolveURL:(MVMCoreSessionObject *)sessionObject { @@ -137,7 +135,7 @@ url = [url URLByAppendingPathComponent:self.pageType]; } - _url = url; + _URL = url; return url; } From c10cb0792e65a8b9858cb074bb9c48c220113df0 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Mon, 24 Apr 2023 15:43:38 +0530 Subject: [PATCH 55/68] updated request url --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 29dd440..0b72002 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -172,7 +172,7 @@ NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; if(!self.backgroundLoad && loadObject.requestParameters.pageType && serverProcessTime) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:@"requestURL" requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:[[loadObject.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]] absoluteString] requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; } // Process the data retrieved from the server. From 27f138d6c1b3e4cd277170f5cac4ad303671474f Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Mon, 24 Apr 2023 23:06:17 +0530 Subject: [PATCH 56/68] updated to requestParameters.URL --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 0b72002..4884007 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -172,7 +172,7 @@ NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; if(!self.backgroundLoad && loadObject.requestParameters.pageType && serverProcessTime) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:[[loadObject.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]] absoluteString] requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; } // Process the data retrieved from the server. From 85f70964996e582780b40c074a35f59ef276bf6b Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 25 Apr 2023 18:35:18 +0530 Subject: [PATCH 57/68] updated request url --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 4884007..b3cedf5 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -163,7 +163,7 @@ } else { if(!self.backgroundLoad && loadObject.requestParameters.pageType) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadStartedFor:loadObject.requestParameters.pageType requestUUID:loadObject.identifier requestURL:@"requestURL"]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadStartedFor:loadObject.requestParameters.pageType requestUUID:loadObject.identifier requestURL:loadObject.requestParameters.URL.absoluteString]; } // Send a new request to the server. From 3d1f1617c5b5aa4c7a92ec562e4c8cc09963d932 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Fri, 28 Apr 2023 21:05:37 +0530 Subject: [PATCH 58/68] added identifier in requestparameters & correlationId --- MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift | 1 + MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m | 2 +- MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m | 3 +++ MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 7 +++---- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h | 3 +++ MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 7 ++++--- MVMCore/MVMCore/Utility/MVMCoreErrorObject.h | 3 --- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 8e1981f..ea40b42 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -44,6 +44,7 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { /// Adds client parameters and makes calls performRequest() open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { let actionUUID = MVMCoreActionHandler.getUUID(additionalData: additionalData) ?? UUID().uuidString + requestParameters.identifier = actionUUID if !requestParameters.backgroundRequest, let pageType = requestParameters.pageType { MVMCoreLoggingHandler.shared()?.logCoreEvent(.pageStarted(pageType: pageType, requestUUID: actionUUID)) } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 629f1ab..3e5ae1f 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -114,7 +114,7 @@ error.nativeDrivenErrorScreen = YES; error.silentError = NO; error.messageToDisplay = error.messageToDisplay ?: [MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess]; - error.identifier = loadObject.identifier; + error.requestId = loadObject.identifier; //To track for errors due to invalid JSON or any errors thrown at viewcontroller level. } return error; } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m index 25240c4..3be1428 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadObject.m @@ -55,6 +55,9 @@ if (errorObject.messageToDisplay) { [responseInfo setObject:errorObject.messageToDisplay forKey:KeyUserMessage]; } + if (errorObject.requestId) { + self.identifier = errorObject.requestId; + } self.responseInfoMap = responseInfo; } return self; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index b3cedf5..6c6873e 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -156,7 +156,7 @@ MVMCoreRequestParameters *requestForMissingData = [MVMCoreLoadRequestOperation createRequestForDataWithLoadObject:loadObject]; if (!requestForMissingData) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:@"0" requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:@"0" requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache correlationId: nil]; // We have all the needed data, continue with the load. [MVMCoreLoadRequestOperation handleLoadObject:loadObject error:nil]; @@ -170,9 +170,10 @@ [MVMCoreLoadRequestOperation sendRequest:requestForMissingData loadObject:loadObject completionHandler:^(NSDictionary * _Nullable json) { NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; + NSString *correlationId = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"correlationId"]]; if(!self.backgroundLoad && loadObject.requestParameters.pageType && serverProcessTime) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache correlationId:correlationId]; } // Process the data retrieved from the server. @@ -309,11 +310,9 @@ // Error json not correct format. MVMCoreErrorObject *errorObject = [[MVMCoreLoadHandler sharedGlobal] errorForLoadObject:loadObject withTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeJSONNotDictionary domain:ErrorDomainSystem]; - errorObject.identifier = loadObject.identifier; [MVMCoreLoadRequestOperation loadAbortedWithError:errorObject loadObject:loadObject]; } } else { - error.identifier = loadObject.identifier; // Error with the request/response [[MVMCoreLoadHandler sharedGlobal] attachLoadInformation:loadObject toError:error]; [MVMCoreLoadRequestOperation loadAbortedWithError:error loadObject:loadObject]; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index a2ca9bf..28d7f2d 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -101,6 +101,9 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { /// A flag for if it should be a background request or not. @property (assign, nonatomic) BOOL backgroundRequest; +//Unique Identifier for event tracking +@property (nullable, strong, nonatomic) NSString *identifier; + // Creates an object with the given page type and extra parameters. Adds the extra parameters to the standard request parameters. Will add any modules needed by the page type by default. - (nullable instancetype)initWithPageType:(nonnull NSString *)pageType extraParameters:(nullable NSDictionary *)extraParameters; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 3c1d0dd..c95158e 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -98,7 +98,8 @@ public enum MVMCoreEvent { requestUUID: String, serverProcessingTime: String, requestURL: String, - isFromCache: Bool + isFromCache: Bool, + correlationId: String? ) case pageProcessingComplete( @@ -170,8 +171,8 @@ extension MVMCoreLoggingHandler { logCoreEvent(.pageLoadStarted(pageType: pageType, requestUUID: requestUUID, requestURL: requestURL)) } - @objc func logPageLoadComplete(for pageType: String, serverProcessingTime: String, requestURL: String, requestUUID: String, isFromCache: Bool) { - logCoreEvent(.pageLoadComplete(pageType: pageType, requestUUID: requestUUID, serverProcessingTime: serverProcessingTime, requestURL: requestURL, isFromCache: isFromCache)) + @objc func logPageLoadComplete(for pageType: String, serverProcessingTime: String, requestURL: String, requestUUID: String, isFromCache: Bool, correlationId: String?) { + logCoreEvent(.pageLoadComplete(pageType: pageType, requestUUID: requestUUID, serverProcessingTime: serverProcessingTime, requestURL: requestURL, isFromCache: isFromCache, correlationId: correlationId)) } @objc func logPageProcessingComplete(for pageType: String, requestUUID: String, webUrl: String?) { diff --git a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h index c717855..465dc44 100644 --- a/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h +++ b/MVMCore/MVMCore/Utility/MVMCoreErrorObject.h @@ -28,9 +28,6 @@ @property (nonatomic, assign) NSInteger httpStatusCode; @property (nullable, strong, nonatomic) NSDictionary *serverResponseInfo; -//Unique Identifier for event tracking -@property (nonatomic, nonatomic, nonnull) NSString *identifier; - // For the crash log. @property (nullable, strong, nonatomic) NSDictionary *crashLog; From 6372fcb56de1185997ae15412a6d787f13026f99 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 2 May 2023 17:20:05 +0530 Subject: [PATCH 59/68] removed correlationId --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 5 ++--- MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 6c6873e..ffcf1a5 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -156,7 +156,7 @@ MVMCoreRequestParameters *requestForMissingData = [MVMCoreLoadRequestOperation createRequestForDataWithLoadObject:loadObject]; if (!requestForMissingData) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:@"0" requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache correlationId: nil]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:@"0" requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; // We have all the needed data, continue with the load. [MVMCoreLoadRequestOperation handleLoadObject:loadObject error:nil]; @@ -170,10 +170,9 @@ [MVMCoreLoadRequestOperation sendRequest:requestForMissingData loadObject:loadObject completionHandler:^(NSDictionary * _Nullable json) { NSString *serverProcessTime = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"timeStamp"]] ?: @"0"; - NSString *correlationId = [(NSDictionary *)json objectChainOfKeysOrIndexes:@[@"ResponseInfo", @"correlationId"]]; if(!self.backgroundLoad && loadObject.requestParameters.pageType && serverProcessTime) { - [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache correlationId:correlationId]; + [[MVMCoreLoggingHandler sharedLoggingHandler] logPageLoadCompleteFor:loadObject.requestParameters.pageType serverProcessingTime:serverProcessTime requestURL:loadObject.requestParameters.URL.absoluteString requestUUID:loadObject.identifier isFromCache:loadObject.pageDataFromCache]; } // Process the data retrieved from the server. diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index c95158e..3c1d0dd 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -98,8 +98,7 @@ public enum MVMCoreEvent { requestUUID: String, serverProcessingTime: String, requestURL: String, - isFromCache: Bool, - correlationId: String? + isFromCache: Bool ) case pageProcessingComplete( @@ -171,8 +170,8 @@ extension MVMCoreLoggingHandler { logCoreEvent(.pageLoadStarted(pageType: pageType, requestUUID: requestUUID, requestURL: requestURL)) } - @objc func logPageLoadComplete(for pageType: String, serverProcessingTime: String, requestURL: String, requestUUID: String, isFromCache: Bool, correlationId: String?) { - logCoreEvent(.pageLoadComplete(pageType: pageType, requestUUID: requestUUID, serverProcessingTime: serverProcessingTime, requestURL: requestURL, isFromCache: isFromCache, correlationId: correlationId)) + @objc func logPageLoadComplete(for pageType: String, serverProcessingTime: String, requestURL: String, requestUUID: String, isFromCache: Bool) { + logCoreEvent(.pageLoadComplete(pageType: pageType, requestUUID: requestUUID, serverProcessingTime: serverProcessingTime, requestURL: requestURL, isFromCache: isFromCache)) } @objc func logPageProcessingComplete(for pageType: String, requestUUID: String, webUrl: String?) { From e6ca9ec67d9e62430ddf79f8b934414e94c294ec Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Tue, 2 May 2023 20:07:40 +0530 Subject: [PATCH 60/68] Bug fix while setting identifier --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m | 2 ++ MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 3e5ae1f..64d67ce 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -389,6 +389,7 @@ return [self loadBackgroundRequest:requestParameters dataForPage:dataForPage delegateObject:delegateObject]; } else { MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject backgroundLoad:NO]; + loadOperation.identifier = requestParameters.identifier; [self.blockingLoadQueue addOperation:loadOperation]; return loadOperation; } @@ -396,6 +397,7 @@ - (MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject { MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject backgroundLoad:YES]; + loadOperation.identifier = requestParameters.identifier; [self.backgroundLoadQueue addOperation:loadOperation]; return loadOperation; } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index ffcf1a5..931c967 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -48,7 +48,6 @@ self.dataForPage = dataForPage; self.delegateObject = delegateObject; self.backgroundLoad = backgroundLoad; - self.identifier = [NSUUID UUID].UUIDString; } return self; } From 87135f31edfcab4d8aaa51fb2afb4a738610bb00 Mon Sep 17 00:00:00 2001 From: Krishna Kishore Bandaru Date: Wed, 3 May 2023 22:12:09 +0530 Subject: [PATCH 61/68] added public access specifier --- MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift index 3c1d0dd..8ccae44 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreEvent.swift @@ -153,7 +153,7 @@ public enum MVMCoreEvent { } } -extension MVMCoreLoggingHandler { +public extension MVMCoreLoggingHandler { func logCoreEvent(_ event: MVMCoreEvent, at timestamp: Int64 = Date.unixMillisecondsNow()) { recordEvent(event.type.rawValue, attributes: ["timestamp": timestamp, "event": event]) From c21e4b680b3aa538e174b4a5840b6702021302e6 Mon Sep 17 00:00:00 2001 From: "Rajendran, Nandhini" Date: Mon, 15 May 2023 23:03:45 +0000 Subject: [PATCH 62/68] story: story: ONEAPP-4067 Swiftify sessionTimeHandler --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 12 +- .../ActionHandling/ActionRestartHandler.swift | 28 ++- .../MVMCoreLoadRequestOperation.m | 5 +- MVMCore/MVMCore/MVMCore.h | 1 - .../Session/MVMCoreSessionTimeHandler.h | 68 ----- .../Session/MVMCoreSessionTimeHandler.m | 232 ------------------ .../Session/MVMCoreSessionTimeHandler.swift | 202 +++++++++++++++ MVMCore/MVMCore/Singletons/MVMCoreObject.h | 2 +- MVMCore/MVMCore/Singletons/MVMCoreObject.m | 4 +- 9 files changed, 228 insertions(+), 326 deletions(-) delete mode 100644 MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h delete mode 100644 MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m create mode 100644 MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 62ebf04..33bacd8 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -41,8 +41,7 @@ 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */; }; 2723337B28BD534D004EAEE0 /* MVMCoreEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */; }; 2723337D28BD53C2004EAEE0 /* Date+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2723337C28BD53C2004EAEE0 /* Date+Extension.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 */; }; + 60CBD0542A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60CBD0532A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift */; }; 881D26931FCC9D180079C521 /* MVMCoreErrorObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */; }; 881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 881D26901FCC9D180079C521 /* MVMCoreOperation.m */; }; 881D26951FCC9D180079C521 /* MVMCoreErrorObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 881D26911FCC9D180079C521 /* MVMCoreErrorObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -199,8 +198,7 @@ 1DAD0FFD26AAB3FF00216E83 /* ActionRunJavaScriptModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionRunJavaScriptModel.swift; sourceTree = ""; }; 2723337A28BD534D004EAEE0 /* MVMCoreEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreEvent.swift; sourceTree = ""; }; 2723337C28BD53C2004EAEE0 /* Date+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extension.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 = ""; }; + 60CBD0532A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreSessionTimeHandler.swift; sourceTree = ""; }; 881D268F1FCC9D180079C521 /* MVMCoreErrorObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreErrorObject.m; sourceTree = ""; }; 881D26901FCC9D180079C521 /* MVMCoreOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreOperation.m; sourceTree = ""; }; 881D26911FCC9D180079C521 /* MVMCoreErrorObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreErrorObject.h; sourceTree = ""; }; @@ -516,8 +514,7 @@ AF43A70C1FC4F42B008E9347 /* Session */ = { isa = PBXGroup; children = ( - 30349BEF1FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h */, - 30349BF01FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m */, + 60CBD0532A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift */, AF43A74A1FC6109F008E9347 /* MVMCoreSessionObject.h */, AF43A74B1FC6109F008E9347 /* MVMCoreSessionObject.m */, ); @@ -737,7 +734,6 @@ AFBB96EC1FBA4A260008D868 /* MFHardCodedServerResponse.h in Headers */, AFBB96B21FBA3B590008D868 /* MVMCoreGetterUtility.h in Headers */, 8876D5F21FB50AB000EB2E3D /* UIFont+MFSpacing.h in Headers */, - 30349BF11FCCA78A00546A1E /* MVMCoreSessionTimeHandler.h in Headers */, AFBB96931FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.h in Headers */, AFBB96961FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.h in Headers */, AFBB96911FBA3A9A0008D868 /* MVMCoreNavigationOperation.h in Headers */, @@ -915,7 +911,6 @@ 94C014D124211869005811A9 /* ActionRestartModel.swift in Sources */, D288D5F526C6EFE000A5C365 /* MVMCoreLoggingHandler+Extension.swift in Sources */, 946EE1B0237B5EF70036751F /* JSONHelper.swift in Sources */, - 30349BF21FCCA78A00546A1E /* MVMCoreSessionTimeHandler.m in Sources */, D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 94C014D3242119E6005811A9 /* ActionPreviousSubmitModel.swift in Sources */, AF60A7F2289212CA00919EEB /* MVMError.swift in Sources */, @@ -973,6 +968,7 @@ AF69D4F1286E9D8000BC6862 /* ActionNoopHandler.swift in Sources */, 016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */, D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */, + 60CBD0542A02397A00056CB0 /* MVMCoreSessionTimeHandler.swift in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, D268D82C26700292008BD413 /* MVMCoreViewManagerViewControllerProtocolHelper.m in Sources */, 0AEBB84625FA75C000EA80EE /* ActionOpenSMSModel.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift index 29fbf53..a108649 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionRestartHandler.swift @@ -15,21 +15,23 @@ open class ActionRestartHandler: MVMCoreActionHandlerProtocol { guard let model = model as? ActionRestartModel else { return } let _: Void = try await withCheckedThrowingContinuation { continuation in - + // Invalidates the session before restarting. - MVMCoreSessionTimeHandler.sharedSession()?.invalidateSession({ error in - if let error = error { - guard error.code != NSURLErrorCancelled else { + Task { @MainActor in + MVMCoreSessionTimeHandler.shared().invalidateSession({ error in + if let error = error { + guard error.code != NSURLErrorCancelled else { + continuation.resume() + return + } + continuation.resume(throwing: MVMCoreError.errorObject(error)) + } else { + // Restarts the app (forcing any passed in page types). + MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) continuation.resume() - return } - continuation.resume(throwing: MVMCoreError.errorObject(error)) - } else { - // Restarts the app (forcing any passed in page types). - MVMCoreSessionObject.sharedGlobal()?.restartSession(withPageType: model.pageType, request: model.requestURL, parameters: model.extraParameters?.toJSON(), clearAllVariables: true) - continuation.resume() - } - }) - } + }) + } + } } } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 931c967..dd5b822 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -10,7 +10,6 @@ #import "MVMCoreLoadHandler.h" #import "MVMCoreLoadingOverlayHandler.h" #import "MVMCoreCache.h" -#import "MVMCoreSessionTimeHandler.h" #import "MVMCoreLoggingHandler.h" #import "MVMCoreSessionObject.h" #import "MVMCoreViewControllerMappingObject.h" @@ -392,7 +391,9 @@ // Update the session timer on a good response. if (loadObject.extendsAppSession) { - [[MVMCoreSessionTimeHandler sharedSessionHandler] startSessionTimer]; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [[MVMCoreSessionTimeHandler sharedSessionHandler] startSessionTimer]; + }]; } // Adds the modules received from server to any modules we grabbed from the cache. diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index be93c59..fd51f0a 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -81,5 +81,4 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; // Singletons #import -#import #import diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h deleted file mode 100644 index 04e2eeb..0000000 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.h +++ /dev/null @@ -1,68 +0,0 @@ -// -// MVMCoreSessionTimeHandler.h -// myverizon -// -// Created by Scott Pfeil on 2/25/14. -// Copyright (c) 2014 Verizon Wireless. All rights reserved. -// -// Handles the session timer. - -#import - -@class MVMCoreErrorObject; - -@interface MVMCoreSessionTimeHandler : NSObject - -/// The number of seconds ago that we started the last session timer. A value of -1 will be returned for sessions not started. -@property (nonatomic, readonly) NSTimeInterval timeSinceStart; - -/// The number of seconds remaining until a warning will occur. A value of 0 will be returned for sessions not started or warning tracking is not enabled. -@property (nonatomic, readonly) NSTimeInterval remainingTimeUntilWarning; - -/// The number of seconds remaining until a timeout will occur. A value of 0 will be returned for sessions not started or timeout tracking is not enabled. -@property (nonatomic, readonly) NSTimeInterval remainingTimeUntiTimeout; - -/// Keeps track of if the session is currently being timed. Used for entering from the background. -@property (assign, nonatomic, readonly) BOOL sessionBeingTimed; - -/// Keeps track of if the session has already timed out. -@property (assign, nonatomic, readonly) BOOL sessionTimedOut; - -#pragma mark - functions to override - -/// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0. -- (NSTimeInterval)timeUntilWarning; - -/// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0. -- (NSTimeInterval)timeUntilTimeout; - -/// Starts the timeout timer. Override to handle what happens on timeout warning. Should call super if want the timeout timer going. -- (void)sessionTimeoutWarning NS_REQUIRES_SUPER; - -/// Called when the session has timed out. Override to handle what happens on timeout. Should call super. Can be called to force timeout... should never need to call unless simulating timout. -- (void)sessionTimeout:(BOOL)whileInBackground NS_REQUIRES_SUPER; - -/// Keeps the session alive. A boolean for if we should show the alert if there is an error. Does nothing by default. Can override to do something. -- (void)sendKeepAliveToServer:(BOOL)notifyUserIfError; - -/// Invalidates the server session and then calls the completion handler. Error may or may not populate. By default this only calls the completion handler, override to invalidate your server session as you see fit then call completion. -- (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion; - -#pragma mark - Session timer functions - -/// Returns the shared instance of this singleton -+ (nullable instancetype)sharedSessionHandler; - -/// Starts the session timer. Should be called after every response from the server. Happens on the main thread. -- (void)startSessionTimer; - -/// Completely stop the session timer. Should only be used in rare occassions, like on the original wifi screen. -- (void)stopSessionTimer; - -/// Returns whether the app is in session. -- (BOOL)isAppInSession; - -/// Resets everything. -- (void)resetState; - -@end diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m deleted file mode 100644 index 6d6e9cd..0000000 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ /dev/null @@ -1,232 +0,0 @@ -// -// MVMCoreSessionTimeHandler.m -// myverizon -// -// Created by Scott Pfeil on 2/25/14. -// Copyright (c) 2014 Verizon Wireless. All rights reserved. -// - -#import "MVMCoreSessionTimeHandler.h" -#import "MVMCoreLoggingHandler.h" -#import "MVMCoreSessionObject.h" -#import "MVMCoreLoadHandler.h" -#import "MVMCoreLoadingOverlayHandler.h" -#import "MVMCoreGetterUtility.h" -#import "MVMCoreErrorConstants.h" -#import "MVMCoreErrorObject.h" -#import "MVMCoreRequestParameters.h" -#import "NSDictionary+MFConvenience.h" -#import "MVMCoreObject.h" -#import "MVMCoreActionUtility.h" - -@interface MVMCoreSessionTimeHandler () - -@property (strong, nonatomic) NSTimer *sessionWarningTimer; -@property (strong, nonatomic) NSTimer *sessionTimer; - -/// The time that we started the last session timer. -@property (assign, nonatomic, readwrite) NSTimeInterval timeTimerStarted; - -/// Keeps track of if the session is currently being timed. Used for entering from the background. -@property (assign, nonatomic, readwrite) BOOL sessionBeingTimed; - -/// Keeps track of if the session has already timed out. -@property (assign, nonatomic, readwrite) BOOL sessionTimedOut; - -@property (assign, nonatomic) NSTimeInterval secondsUntilWarning; -@property (assign, nonatomic) NSTimeInterval secondsUntilTimeout; - -/// Should be called when the app enters the background. -- (void)appEnteredBackground; - -/// Should be called when the app enters the foreground. -- (void)appEnteredForeground; - -@end - -@implementation MVMCoreSessionTimeHandler - -+ (nullable instancetype)sharedSessionHandler { - return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].sessionHandler classToVerify:self]; -} - -- (instancetype)init { - if (self = [super init]) { - // Adds notifications for if the app entered the background/foreground. - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; - [self resetStartTime]; - } - return self; -} - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil]; -} - -#pragma mark - functions to override - -- (NSTimeInterval)timeUntilWarning { - return 0; -} - -- (NSTimeInterval)timeUntilTimeout { - return 0; -} - -- (void)sessionTimeoutWarning { -} - -- (void)sessionTimeout:(BOOL)whileInBackground { - self.sessionTimedOut = YES; - [self stopSessionTimer]; -} - -- (void)sendKeepAliveToServer:(BOOL)notifyUserIfError { -} - -#pragma mark - State - -- (void)markStartTime { - self.timeTimerStarted = [NSDate timeIntervalSinceReferenceDate]; -} - -- (void)resetStartTime { - self.timeTimerStarted = -1; -} - -- (NSTimeInterval)timeSinceStart { - if (self.timeTimerStarted < 0) { - return -1; - } - return [NSDate timeIntervalSinceReferenceDate] - self.timeTimerStarted; -} - -- (BOOL)isWarningEnabled { - return [self isTimeoutEnabled] && !fequal(0, self.secondsUntilWarning); -} - -- (BOOL)isTimeoutEnabled { - return !fequal(0, self.secondsUntilTimeout); -} - -- (NSTimeInterval)remainingTimeUntilWarning { - if (self.timeTimerStarted < 0 || ![self isWarningEnabled]) { - return 0; - } - return self.secondsUntilWarning - self.timeSinceStart; -} - -- (NSTimeInterval)remainingTimeUntiTimeout { - if (self.timeTimerStarted < 0 || ![self isTimeoutEnabled]) { - return 0; - } - return self.secondsUntilTimeout - self.timeSinceStart; -} - -#pragma mark - Session timer functions - -- (void)startSessionTimer { - dispatch_async(dispatch_get_main_queue(), ^(void) { - - if (!self.sessionTimedOut) { - - [self.sessionWarningTimer invalidate]; - [self.sessionTimer invalidate]; - - self.secondsUntilWarning = [self timeUntilWarning]; - self.secondsUntilTimeout = [self timeUntilTimeout]; - - if (self.isTimeoutEnabled) { - self.sessionBeingTimed = YES; - [self markStartTime]; - [self resumeSessionTimer]; - } - } - }); -} - -/// Resume the session timers if they are stopped. -- (void)resumeSessionTimer { - dispatch_async(dispatch_get_main_queue(), ^(void) { - // Only start physical timer if active, otherwise will begin once entering foreground. FaceId prompt is considered UIApplicationStateInactive. - if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { - return; - } - - if (self.isTimeoutEnabled && ![self.sessionTimer isValid]) { - // Session timeout, implicitly whileInBackround as no. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. - self.sessionTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntiTimeout] target:self selector:@selector(sessionTimeout:) userInfo:nil repeats:NO]; - MVMCoreLog(@"Session timeout will fire at: %@", self.sessionTimer.fireDate); - - // Only setup a warning timer if there is a timeout timer. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. - if (self.isWarningEnabled && ![self.sessionWarningTimer isValid]) { - self.sessionWarningTimer = [NSTimer scheduledTimerWithTimeInterval:[self remainingTimeUntilWarning] target:self selector:@selector(sessionTimeoutWarning) userInfo:nil repeats:NO]; - MVMCoreLog(@"Session warning will fire at: %@", self.sessionWarningTimer.fireDate); - } - } - }); -} - -- (void)stopSessionTimer { - - // nil timer, session no longer timed. - dispatch_async(dispatch_get_main_queue(), ^(void) { - self.sessionBeingTimed = NO; - [self.sessionWarningTimer invalidate]; - self.sessionWarningTimer = nil; - [self.sessionTimer invalidate]; - self.sessionTimer = nil; - }); -} - -- (void)appEnteredBackground { - - // Session is still being timed. Invalidates here, will start up again on enter foreground if need be. - dispatch_async(dispatch_get_main_queue(), ^(void) { - [self.sessionWarningTimer invalidate]; - self.sessionWarningTimer = nil; - [self.sessionTimer invalidate]; - self.sessionTimer = nil; - }); -} - -- (void)appEnteredForeground { - // Special return logic to cancel when returning in warning track. This is not in the revalidateSessionTimestamp in order to prevent API checks to isAppInSession from timing out the session from under the user warning period. - if (self.isWarningEnabled && self.remainingTimeUntilWarning < 0) { - [self sessionTimeout:YES]; - } - - // Revalidate first to check if we should be in the timeout state. - [self revalidateSessionTimestamp]; - [self sendKeepAliveToServer:NO]; -} - -- (void)invalidateSession:(void (^ __nullable)(MVMCoreErrorObject * _Nullable error))completion { - completion(nil); -} - -// Checks to make sure session is still valid and that the timer is running. -- (void)revalidateSessionTimestamp { - if (self.sessionBeingTimed || self.sessionTimedOut) { - if (self.isTimeoutEnabled && self.remainingTimeUntiTimeout < 0) { - // Force a timeout if we are passed the timeout interval. - [self sessionTimeout:YES]; - } else { - [self resumeSessionTimer]; - } - } -} - -- (BOOL)isAppInSession { - [self revalidateSessionTimestamp]; // Possible race condition hazard. Session timeouts will happen as if they are in background. If isAppInSession is called right before foreground trigger, it could potentially suppress the dialog. - return self.sessionBeingTimed && !self.sessionTimedOut; -} - -- (void)resetState { - [self stopSessionTimer]; - self.sessionTimedOut = NO; -} - -@end diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift new file mode 100644 index 0000000..068d0d2 --- /dev/null +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift @@ -0,0 +1,202 @@ +// +// MVMCoreSessionTimeHandler.swift +// MVMCore +// +// Created by Nandhini Rajendran on 03/05/23. +// Copyright © 2023 myverizon. All rights reserved. +// +// Managed on the main thread because of the run loop requirements of the timers. + +@MainActor +@objc open class MVMCoreSessionTimeHandler: NSObject { + /// Keeps track of if the session is currently being timed. Used for entering from the background. + public var sessionBeingTimed: Bool = false + /// Keeps track of if the session has already timed out. + public var sessionTimedOut: Bool = false + private var sessionWarningTimer: Timer? + private var sessionTimer: Timer? + /// The time that we started the last session timer. + private var timeTimerStarted: TimeInterval? + private var secondsUntilWarning: TimeInterval = 0 + private var secondsUntilTimeout: TimeInterval = 0 + + @objc(sharedSessionHandler) + public static func shared() -> Self { + return MVMCoreActionUtility.fatalClassCheck(object: MVMCoreObject.sharedInstance()?.sessionHandler) + } + + public override init() { + super.init() + // Adds notifications for if the app entered the background/foreground. + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + resetStartTime() + } + + deinit { + Task { @MainActor in + NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil) + } + } + + // MARK: - functions to override + + /// Can override to provide a time until the warning shows in seconds. Set to 0 if there should be no warning. Default is 0. + open func timeUntilWarning() -> TimeInterval { + return 0 + } + + /// Can override to provide a time until the timeout happens in seconds. If there is a warning, then this value is used after the warning happens. Set to 0 if there should be no timeout. Default is 0. + open func timeUntilTimeout() -> TimeInterval { + return 0 + } + + /// Starts the timeout timer. Override to handle what happens on timeout warning. Should call super if want the timeout timer going. + @objc open func sessionTimeoutWarning() { } + + /// Called when the session has timed out. Override to handle what happens on timeout. Should call super. Can be called to force timeout... should never need to call unless simulating timout. + @objc open func sessionTimeout(_ whileInBackground: Bool) { + sessionTimedOut = true + stopSessionTimer() + } + + /// Keeps the session alive. A boolean for if we should show the alert if there is an error. Does nothing by default. Can override to do something. + @objc(sendKeepAliveToServer:) + open func sendKeepAlive(toServer notifyUserIfError: Bool) { } + + // MARK: - State + func markStartTime() { + timeTimerStarted = Date().timeIntervalSinceReferenceDate + } + + func resetStartTime() { + timeTimerStarted = nil + } + + /// The number of seconds ago that we started the last session timer. A value of nil will be returned for sessions not started. + public func timeSinceStart() -> TimeInterval? { + guard let timeTimerStarted = timeTimerStarted else { return nil } + return Date().timeIntervalSinceReferenceDate - timeTimerStarted + } + + func isWarningEnabled() -> Bool { + return isTimeoutEnabled() && !MVMCoreGetterUtility.fequal(a: 0, b: Float(secondsUntilWarning)) + } + + func isTimeoutEnabled() -> Bool { + return !MVMCoreGetterUtility.fequal(a: 0, b: Float(secondsUntilTimeout)) + } + + /// The number of seconds remaining until a warning will occur. A value of nil will be returned for sessions not started or warning tracking is not enabled. + func remainingTimeUntilWarning() -> TimeInterval? { + guard isWarningEnabled(), + let timeTimerStarted = timeSinceStart() else { return nil } + return secondsUntilWarning - timeTimerStarted + } + + /// The number of seconds remaining until a timeout will occur. A value of nil will be returned for sessions not started or timeout tracking is not enabled. + public func remainingTimeUntiTimeout() -> TimeInterval? { + guard isTimeoutEnabled(), + let timeTimerStarted = timeSinceStart() else { return nil } + return secondsUntilTimeout - timeTimerStarted + } + + // MARK: - Session timer functions + + /// Starts the session timer. Should be called after every response from the server. Happens on the main thread. + @objc public func startSessionTimer() { + guard !sessionTimedOut else { return } + sessionWarningTimer?.invalidate() + sessionTimer?.invalidate() + + secondsUntilWarning = timeUntilWarning() + secondsUntilTimeout = timeUntilTimeout() + + guard isTimeoutEnabled() else { return } + sessionBeingTimed = true + markStartTime() + resumeSessionTimer() + } + + /// Resume the session timers if they are stopped. + func resumeSessionTimer() { + // Only start physical timer if active, otherwise will begin once entering foreground. FaceId prompt is considered UIApplicationStateInactive. + guard UIApplication.shared.applicationState != UIApplication.State.background, + let remainingTimeUntiTimeout = remainingTimeUntiTimeout(), + !(sessionTimer?.isValid ?? false) else { return } + // Session timeout, implicitly whileInBackround as no. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. + sessionTimer = Timer.scheduledTimer(timeInterval: remainingTimeUntiTimeout, target: self, selector: #selector(sessionTimeout(_:)), userInfo: nil, repeats: false) + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Session timeout will fire at: \(String(describing: sessionTimer?.fireDate)))") + + // Only setup a warning timer if there is a timeout timer. Note based on scheduledTimerWithTimeInterval, if the remaining time < 0, this will fire near immediately. + guard let remainingTimeUntilWarning = remainingTimeUntilWarning(), + !(self.sessionWarningTimer?.isValid ?? false) else { return } + sessionWarningTimer = Timer.scheduledTimer(timeInterval: remainingTimeUntilWarning, target: self, selector: #selector(sessionTimeoutWarning), userInfo: nil, repeats: false) + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Session warning will fire at: \(String(describing: sessionWarningTimer?.fireDate)))") + } + + /// Completely stop the session timer. Should only be used in rare occassions, like on the original wifi screen. + @objc public func stopSessionTimer() { + // nil timer, session no longer timed. + sessionBeingTimed = false + sessionWarningTimer?.invalidate() + sessionWarningTimer = nil + sessionTimer?.invalidate() + sessionTimer = nil + } + + /// Should be called when the app enters the background. + @objc nonisolated func appEnteredBackground() { + // Session is still being timed. Invalidates here, will start up again on enter foreground if need be. + Task { @MainActor in + self.sessionWarningTimer?.invalidate() + self.sessionWarningTimer = nil + self.sessionTimer?.invalidate() + self.sessionTimer = nil + } + } + + /// Should be called when the app enters the foreground. + @objc nonisolated func appEnteredForeground() { + // Special return logic to cancel when returning in warning track. This is not in the revalidateSessionTimestamp in order to prevent API checks to isAppInSession from timing out the session from under the user warning period. + Task { @MainActor in + if let remainingTimeUntilWarning = self.remainingTimeUntilWarning(), + remainingTimeUntilWarning < 0 { + self.sessionTimeout(true) + } + + // Revalidate first to check if we should be in the timeout state. + self.revalidateSessionTimestamp() + self.sendKeepAlive(toServer: false) + } + } + + @objc open func invalidateSession(_ completion: ((MVMCoreErrorObject?) -> Void)? = nil) { + completion?(nil) + } + + /// Checks to make sure session is still valid and that the timer is running. + func revalidateSessionTimestamp() { + guard sessionBeingTimed || sessionTimedOut else { return } + if let remainingTimeUntiTimeout = remainingTimeUntiTimeout(), + remainingTimeUntiTimeout < 0 { + // Force a timeout if we are passed the timeout interval. + sessionTimeout(true) + } else { + resumeSessionTimer() + } + } + + /// Returns whether the app is in session. + @objc open func isAppInSession() -> Bool { + revalidateSessionTimestamp() // Possible race condition hazard. Session timeouts will happen as if they are in background. If isAppInSession is called right before foreground trigger, it could potentially suppress the dialog. + return sessionBeingTimed && !sessionTimedOut + } + + /// Resets everything. + public func resetState() { + stopSessionTimer() + sessionTimedOut = false + } +} diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.h b/MVMCore/MVMCore/Singletons/MVMCoreObject.h index be532a7..dd7f22f 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.h +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.h @@ -10,13 +10,13 @@ #import #import #import -#import #import #import #import #import #import @class MVMCoreActionHandler; +@class MVMCoreSessionTimeHandler; @interface MVMCoreObject : NSObject diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.m b/MVMCore/MVMCore/Singletons/MVMCoreObject.m index 21eb44e..2bbeb06 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.m +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.m @@ -25,7 +25,9 @@ self.session = [[MVMCoreSessionObject alloc] init]; self.cache = [[MVMCoreCache alloc] init]; self.viewControllerMapping = [[MVMCoreViewControllerMappingObject alloc] init]; - self.sessionHandler = [[MVMCoreSessionTimeHandler alloc] init]; + [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ + self.sessionHandler = [[MVMCoreSessionTimeHandler alloc] init]; + }]; self.actionHandler = [[MVMCoreActionHandler alloc] init]; self.loggingDelegate = [[MVMCoreLoggingHandler alloc] init]; self.loadHandler = [[MVMCoreLoadHandler alloc] init]; From cba4af9ce8c0fcc7b2ddd94f6ff1ffbb38586a34 Mon Sep 17 00:00:00 2001 From: Kyle Hedden Date: Wed, 14 Jun 2023 19:47:26 -0400 Subject: [PATCH 63/68] Allow session handler objects to be initialized without MainActor to inline session creation with async await incompatible code. Fixes a Main thread dispatch clash. --- .../MVMCore/Session/MVMCoreSessionTimeHandler.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift index 068d0d2..7f8d0ef 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.swift @@ -25,12 +25,14 @@ return MVMCoreActionUtility.fatalClassCheck(object: MVMCoreObject.sharedInstance()?.sessionHandler) } - public override init() { + nonisolated public override init() { super.init() - // Adds notifications for if the app entered the background/foreground. - NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil) - resetStartTime() + + Task { @MainActor in + // Adds notifications for if the app entered the background/foreground. + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackground), name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(appEnteredForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + } } deinit { From 53634fcaa13861bd2ecf90628a9915253c98d663 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 15 Jun 2023 12:12:03 -0400 Subject: [PATCH 64/68] ONEAPP-3998: Convenience function to simplify the current objc-swift bridge of having two action protocols. --- MVMCore/MVMCore/ActionHandling/ActionDelegateProtocol.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MVMCore/MVMCore/ActionHandling/ActionDelegateProtocol.swift b/MVMCore/MVMCore/ActionHandling/ActionDelegateProtocol.swift index 6788d08..c927e9a 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionDelegateProtocol.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionDelegateProtocol.swift @@ -19,3 +19,9 @@ public extension ActionDelegateProtocol { try await MVMCoreActionHandler.shared()?.handleAction(with: model, additionalData: additionalData, delegateObject: delegateObject) } } + +public extension MVMCoreActionDelegateProtocol { + func action(with model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) async throws { + try await (self as? ActionDelegateProtocol)?.performAction(with: model, additionalData: additionalData, delegateObject: delegateObject) + } +} From 3383d71c1948cbeebf26ffdfa58c535243786963 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Thu, 15 Jun 2023 12:16:17 -0400 Subject: [PATCH 65/68] ONEAPP-3998: Allow a chance to override code. --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 3 ++- MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 621a057..012d0ca 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -371,10 +371,11 @@ return; } +#if TESTING if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(modifyJSON:)]) { jsonDictionary = [[MVMCoreObject sharedInstance].globalLoadDelegate modifyJSON:jsonDictionary]; } - +#endif loadObject.responseJSON = jsonDictionary; // Store the new page data if we didn't load page data from the cache. diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h index bd2c82d..9dc7d78 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h @@ -16,7 +16,10 @@ @optional +#if TESTING +/// Allows a chance to modify the json and provide local test json. - (nonnull NSDictionary *)modifyJSON:(nonnull NSDictionary *)json; +#endif // Provides the desired error screen for the native error. Called on the main thread. If set, any native errors or NSURLErrorDomain errors will use a native screen. - (nullable UIViewController *)getNativeScreenForRequestError:(nonnull MVMCoreErrorObject *)errorObject requestObject:(nonnull MVMCoreRequestParameters *)requestObject; @@ -43,4 +46,6 @@ /// Checks to see if the operation has content to show. - (BOOL)hasContentToShow:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error; +- (nonnull NSDictionary *)getJSON:(nonnull NSDictionary *)json; + @end From ce246523acff86a900e771024802db8231514fec Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Tue, 20 Jun 2023 16:07:47 -0400 Subject: [PATCH 66/68] remove old test code --- MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h index 9dc7d78..2b66238 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h @@ -46,6 +46,4 @@ /// Checks to see if the operation has content to show. - (BOOL)hasContentToShow:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error; -- (nonnull NSDictionary *)getJSON:(nonnull NSDictionary *)json; - @end From 05289f88aaf5379f5231f30ffbde7068bb0e2e90 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Wed, 21 Jun 2023 12:11:15 -0400 Subject: [PATCH 67/68] main thread change for session handler --- MVMCore/MVMCore/Singletons/MVMCoreObject.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.m b/MVMCore/MVMCore/Singletons/MVMCoreObject.m index 2bbeb06..21eb44e 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.m +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.m @@ -25,9 +25,7 @@ self.session = [[MVMCoreSessionObject alloc] init]; self.cache = [[MVMCoreCache alloc] init]; self.viewControllerMapping = [[MVMCoreViewControllerMappingObject alloc] init]; - [MVMCoreDispatchUtility performSyncBlockOnMainThread:^{ - self.sessionHandler = [[MVMCoreSessionTimeHandler alloc] init]; - }]; + self.sessionHandler = [[MVMCoreSessionTimeHandler alloc] init]; self.actionHandler = [[MVMCoreActionHandler alloc] init]; self.loggingDelegate = [[MVMCoreLoggingHandler alloc] init]; self.loadHandler = [[MVMCoreLoadHandler alloc] init]; From 25394dc6407ec3a9c6e58ef651abc65c322aade2 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Wed, 21 Jun 2023 12:23:59 -0400 Subject: [PATCH 68/68] remove debug code for now --- MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m | 5 ----- MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h | 5 ----- 2 files changed, 10 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 012d0ca..dd5b822 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -371,11 +371,6 @@ return; } -#if TESTING - if ([[MVMCoreObject sharedInstance].globalLoadDelegate respondsToSelector:@selector(modifyJSON:)]) { - jsonDictionary = [[MVMCoreObject sharedInstance].globalLoadDelegate modifyJSON:jsonDictionary]; - } -#endif loadObject.responseJSON = jsonDictionary; // Store the new page data if we didn't load page data from the cache. diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h index 2b66238..65ea153 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreGlobalLoadProtocol.h @@ -16,11 +16,6 @@ @optional -#if TESTING -/// Allows a chance to modify the json and provide local test json. -- (nonnull NSDictionary *)modifyJSON:(nonnull NSDictionary *)json; -#endif - // Provides the desired error screen for the native error. Called on the main thread. If set, any native errors or NSURLErrorDomain errors will use a native screen. - (nullable UIViewController *)getNativeScreenForRequestError:(nonnull MVMCoreErrorObject *)errorObject requestObject:(nonnull MVMCoreRequestParameters *)requestObject;