Merge branch 'release/8_4_0' into 'develop'
release/8_4_0 hotfix merge See merge request BPHV_MIPS/mvm_core!134
This commit is contained in:
commit
97216b9dfe
@ -21,6 +21,11 @@
|
||||
/* End PBXAggregateTarget section */
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */; };
|
||||
016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */; };
|
||||
016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */; };
|
||||
016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */; };
|
||||
01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */; };
|
||||
01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; };
|
||||
01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; };
|
||||
01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; };
|
||||
@ -144,6 +149,11 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModelProtocol.swift; sourceTree = "<group>"; };
|
||||
016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModel.swift; sourceTree = "<group>"; };
|
||||
016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterRegistry.swift; sourceTree = "<group>"; };
|
||||
016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterProtocol.swift; sourceTree = "<group>"; };
|
||||
01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterActionProtocol.swift; sourceTree = "<group>"; };
|
||||
01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = "<group>"; };
|
||||
01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = "<group>"; };
|
||||
01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = "<group>"; };
|
||||
@ -286,6 +296,18 @@
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
016FF6EC259A4E3E00F5E4AA /* Client Parameters */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */,
|
||||
016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */,
|
||||
016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */,
|
||||
016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */,
|
||||
01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */,
|
||||
);
|
||||
path = "Client Parameters";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8876D5BF1FB50A9E00EB2E3D = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -405,6 +427,7 @@
|
||||
946EE1B6237B66630036751F /* ActionType */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
016FF6EC259A4E3E00F5E4AA /* Client Parameters */,
|
||||
01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */,
|
||||
946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */,
|
||||
01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */,
|
||||
@ -820,6 +843,7 @@
|
||||
AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */,
|
||||
8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */,
|
||||
01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */,
|
||||
01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */,
|
||||
AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */,
|
||||
AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */,
|
||||
AFED77A61FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m in Sources */,
|
||||
@ -830,6 +854,7 @@
|
||||
8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */,
|
||||
AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */,
|
||||
AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */,
|
||||
016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */,
|
||||
94C014D924212360005811A9 /* ActionSettingModel.swift in Sources */,
|
||||
D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */,
|
||||
01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */,
|
||||
@ -845,10 +870,13 @@
|
||||
AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */,
|
||||
94C014D524211AF0005811A9 /* ActionCancelModel.swift in Sources */,
|
||||
AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */,
|
||||
016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */,
|
||||
D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */,
|
||||
AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */,
|
||||
016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */,
|
||||
8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */,
|
||||
D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */,
|
||||
016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@ -158,4 +158,6 @@ extern NSString * _Nonnull const KeyActionTypeOpen;
|
||||
// By default, throws an error, calling defaultHandleActionError.
|
||||
+ (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Iterates through the clientParameters list. Gets values from the individual handlers and attaches the parameters to extraParameters.
|
||||
- (void)setClientParameter:(nullable NSDictionary *)actionInformation completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler;
|
||||
@end
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#import "MVMCorePresentationDelegateProtocol.h"
|
||||
#import <SafariServices/SafariServices.h>
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
#import "MVMCoreLoadingOverlayHandler.h"
|
||||
|
||||
NSString * const KeyActionType = @"actionType";
|
||||
NSString * const KeyActionTypeLinkAway = @"openURL";
|
||||
@ -107,22 +108,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
|
||||
// Loads the given page type.
|
||||
NSString *pageType = [actionInformation stringForKey:KeyPageType];
|
||||
if (pageType.length > 0) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation];
|
||||
|
||||
[self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
|
||||
if (pageType.length == 0) {
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap];
|
||||
|
||||
[weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
};
|
||||
|
||||
[self setClientParameter:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -266,23 +273,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
#pragma mark - open url functions
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionInformation string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionMap string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionMap string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject];
|
||||
};
|
||||
|
||||
[self setClientParameter:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -411,22 +423,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
|
||||
// Loads the given page type.
|
||||
NSString *pageType = [actionInformation stringForKey:KeyPageType];
|
||||
if (pageType.length > 0) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation];
|
||||
|
||||
[self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
|
||||
if (pageType.length == 0) {
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap];
|
||||
|
||||
[weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) {
|
||||
[delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData];
|
||||
[delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionMap additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
}
|
||||
};
|
||||
|
||||
[self setClientParameter:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
@ -524,23 +542,76 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionMap string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionMap string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate];
|
||||
};
|
||||
|
||||
[self setClientParameter:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)setClientParameter:(nullable NSDictionary *)actionInformation completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler {
|
||||
|
||||
NSDictionary *clientParametersMap = [actionInformation dict:KeyClientParameters];
|
||||
if (!clientParametersMap) {
|
||||
completionHandler(actionInformation);
|
||||
return;
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionInformation string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
|
||||
BOOL isBackgroudRequest = [actionInformation boolForKey:@"background"];
|
||||
|
||||
if (!isBackgroudRequest) {
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading];
|
||||
}
|
||||
|
||||
void (^stopLoadingOverlay)(void) = ^(void) {
|
||||
if (!isBackgroudRequest) {
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:true];
|
||||
}
|
||||
};
|
||||
|
||||
NSError *error = nil;
|
||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Fetching client parameters"];
|
||||
[[[MVMCoreObject sharedInstance] clientParameterRegistry] getParametersWith:clientParametersMap
|
||||
error:&error
|
||||
completionHandler:^(NSDictionary<NSString *,id> * _Nullable clientParameters) {
|
||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Finshed fetching client parameters"];
|
||||
if (clientParameters) {
|
||||
NSMutableDictionary *actionWithClientParameters = [actionInformation mutableCopy];
|
||||
NSMutableDictionary *extraParameters = [clientParameters mutableCopy];
|
||||
[extraParameters addEntriesFromDictionary:[actionWithClientParameters dictionaryForKey:KeyExtraParameters]];
|
||||
actionWithClientParameters[KeyExtraParameters] = extraParameters;
|
||||
|
||||
stopLoadingOverlay();
|
||||
completionHandler(actionWithClientParameters);
|
||||
} else {
|
||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client parameters"];
|
||||
stopLoadingOverlay();
|
||||
completionHandler(actionInformation);
|
||||
}
|
||||
}];
|
||||
|
||||
if (error) {
|
||||
stopLoadingOverlay();
|
||||
completionHandler(actionInformation);
|
||||
[MVMCoreLoggingHandler addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreActionHandler->setClientParameter"]];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
@ -51,6 +51,8 @@ extern NSString * const KeyContextRoot;
|
||||
extern NSString * const KeyType;
|
||||
extern NSString * const KeyMVMRC;
|
||||
|
||||
extern NSString * const KeyClientParameters;
|
||||
|
||||
#pragma mark - JSON Values
|
||||
|
||||
// Server driven response type
|
||||
|
||||
@ -51,6 +51,8 @@ NSString * const KeyContextRoot = @"appContext";
|
||||
NSString * const KeyType = @"type";
|
||||
NSString * const KeyMVMRC = @"LaunchMVMRC";
|
||||
|
||||
NSString * const KeyClientParameters = @"clientParameters";
|
||||
|
||||
#pragma mark - JSON Values
|
||||
|
||||
// Server driven response type
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
|
||||
@objcMembers open class ActionOpenPageModel: ActionModelProtocol {
|
||||
@objcMembers open class ActionOpenPageModel: ActionModelProtocol, ClientParameterActionProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -20,7 +20,8 @@
|
||||
public var presentationStyle: String?
|
||||
public var tabBarIndex: Int?
|
||||
public var background: Bool?
|
||||
|
||||
public var clientParameters: ClientParameterModel?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initialzier
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
|
||||
@objcMembers public class ActionOpenUrlModel: ActionModelProtocol {
|
||||
@objcMembers public class ActionOpenUrlModel: ActionModelProtocol, ClientParameterActionProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -18,6 +18,7 @@
|
||||
public var browserUrl: String
|
||||
public var extraParameters: JSONValueDictionary?
|
||||
public var analyticsData: JSONValueDictionary?
|
||||
public var clientParameters: ClientParameterModel?
|
||||
public var appURL: String?
|
||||
|
||||
//TODO: Should be removed in future releases. This should be MF specific.
|
||||
@ -30,6 +31,7 @@
|
||||
public var dontShowProgress: Bool?
|
||||
public var headerParameters: JSONValueDictionary?
|
||||
public var enableNativeScroll: Bool?
|
||||
public var hideUrl: Bool?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initialzier
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
//
|
||||
// ClientParameterActionProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 1/5/21.
|
||||
// Copyright © 2021 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterActionProtocol {
|
||||
var clientParameters: ClientParameterModel? { get set }
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
//
|
||||
// ClientParameterModel.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/28/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ClientParameterModel: Codable {
|
||||
var timeout: Double?
|
||||
var list: [ClientParameterModelProtocol]
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case timeout
|
||||
case list
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
timeout = try typeContainer.decodeIfPresent(Double.self, forKey: .timeout)
|
||||
list = try typeContainer.decodeModels(codingKey: .list)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(timeout, forKey: .timeout)
|
||||
try container.encodeModels(list, forKey: .list)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
//
|
||||
// ClientParameterProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/28/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterModelProtocol: ModelProtocol {
|
||||
var type: String { get }
|
||||
}
|
||||
|
||||
public extension ClientParameterModelProtocol {
|
||||
|
||||
var type: String {
|
||||
get { Self.identifier }
|
||||
}
|
||||
|
||||
static var categoryCodingKey: String {
|
||||
return "type"
|
||||
}
|
||||
|
||||
static var categoryName: String {
|
||||
return "\(ClientParameterModelProtocol.self)"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
//
|
||||
// ClientParameterProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/29/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterProtocol {
|
||||
init()
|
||||
static var name: String { get }
|
||||
func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping (AnyHashable?) -> ())
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
//
|
||||
// ClientParameterRegistry.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/29/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers open class ClientParameterRegistry: NSObject {
|
||||
|
||||
private var mapping: [String: ClientParameterProtocol.Type] = [:]
|
||||
|
||||
|
||||
public override init() {
|
||||
super.init()
|
||||
registerParameters()
|
||||
}
|
||||
|
||||
open func register<T:ClientParameterProtocol>(_ handler: T.Type) {
|
||||
mapping[T.name] = handler
|
||||
}
|
||||
|
||||
open func createParametersHandler(_ actionType: String) -> ClientParameterProtocol? {
|
||||
guard let parameterType = mapping[actionType] else { return nil }
|
||||
return parameterType.init()
|
||||
}
|
||||
|
||||
static func getClientParameterModel(_ clientParameters: [String: Any]) throws -> ClientParameterModel? {
|
||||
let data = try JSONSerialization.data(withJSONObject: clientParameters)
|
||||
return try JSONDecoder().decode(ClientParameterModel.self, from: data)
|
||||
}
|
||||
|
||||
/// Sample clientParameters
|
||||
///{
|
||||
/// "timeout": 30,
|
||||
/// "list": [
|
||||
/// {
|
||||
/// "type": "currentLocation",
|
||||
/// "inputParameters": {
|
||||
/// "accuracy": 10,
|
||||
/// "timeThreshold": 600
|
||||
/// }
|
||||
/// }
|
||||
/// ]
|
||||
///}
|
||||
/// completionHandler can return flat dictinary or a map. It depends on the paramters handler
|
||||
open func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws {
|
||||
|
||||
guard let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else {
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
var parametersList: [String: Any] = [:]
|
||||
let timeout = clientParameterModel.timeout ?? 30.0
|
||||
|
||||
let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter")
|
||||
let group = DispatchGroup()
|
||||
let defaultErrorString = "failed_to_collect."
|
||||
|
||||
// Dispatch setup on queue to ensure setup is complete before completion callbacks.
|
||||
parametersWorkQueue.async(group: group, qos: .userInitiated) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
// Setup completion handlers. Barriered to ensure one happens after the other.
|
||||
var complete = false
|
||||
let timeoutWorkItem = DispatchWorkItem(qos: .userInitiated) {
|
||||
completionHandler(parametersList);
|
||||
complete = true
|
||||
}
|
||||
let completionWorkItem = DispatchWorkItem(qos: .userInitiated) {
|
||||
timeoutWorkItem.cancel()
|
||||
if !complete { // In the case of firing after timeout.
|
||||
completionHandler(parametersList);
|
||||
complete = true
|
||||
}
|
||||
}
|
||||
|
||||
// Setup timeout.
|
||||
parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem)
|
||||
|
||||
// Setup the parameter execution.
|
||||
for parameterModel in clientParameterModel.list {
|
||||
// Setup default timeout / nil error. This will be replaced as parameters are collected.
|
||||
parametersList[parameterModel.type] = ["error": defaultErrorString]
|
||||
group.enter()
|
||||
// Dispatch asynchronous injection.
|
||||
self.getParameterFromHandler(parameterModel, before: timeout) { (receivedParameter) in
|
||||
// Queue the results for merge.
|
||||
parametersWorkQueue.async {
|
||||
if let receivedParameter = receivedParameter {
|
||||
parametersList[parameterModel.type] = receivedParameter
|
||||
}
|
||||
group.leave() // Leaving is only done after setup (barriered).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Callback when all parameters have been merged.
|
||||
group.notify(queue: parametersWorkQueue, work: completionWorkItem);
|
||||
}
|
||||
}
|
||||
|
||||
func getParameterFromHandler( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) {
|
||||
guard let parameterHandler = createParametersHandler(parameterModel.type) else {
|
||||
return completionHandler(nil)
|
||||
}
|
||||
parameterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
/// Add all registry here.
|
||||
open func registerParameters() { }
|
||||
|
||||
/// Register Default Core Client Paramter Objects
|
||||
public func register<T:ClientParameterProtocol, M: ModelProtocol>(handler: T.Type, for model: M.Type) throws {
|
||||
try ModelRegistry.register(model)
|
||||
register(handler)
|
||||
}
|
||||
|
||||
/// Register Default Core Client Paramter Objects
|
||||
public static func register<T:ClientParameterProtocol, M: ModelProtocol>(handler: T.Type, for model: M.Type) throws {
|
||||
try ModelRegistry.register(model)
|
||||
MVMCoreObject.sharedInstance()?.clientParameterRegistry?.register(handler)
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,8 @@
|
||||
#import <MVMCore/MVMCoreLoggingHandler.h>
|
||||
#import <MVMCore/MVMCoreLoadHandler.h>
|
||||
|
||||
@class ClientParameterRegistry;
|
||||
|
||||
@interface MVMCoreObject : NSObject
|
||||
|
||||
@property (nullable, strong, nonatomic) MVMCoreSessionObject *session;
|
||||
@ -26,6 +28,7 @@
|
||||
@property (nullable, strong, nonatomic) MVMCoreActionHandler *actionHandler;
|
||||
@property (nullable, strong, nonatomic) MVMCoreSessionTimeHandler *sessionHandler;
|
||||
@property (nullable, strong, nonatomic) MVMCoreLoadHandler *loadHandler;
|
||||
@property (nullable, strong, nonatomic) ClientParameterRegistry *clientParameterRegistry;
|
||||
|
||||
// The delegates
|
||||
@property (nullable, strong, nonatomic) id <MVMCoreGlobalLoadProtocol> globalLoadDelegate;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "MVMCoreObject.h"
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
@implementation MVMCoreObject
|
||||
|
||||
@ -27,6 +28,7 @@
|
||||
self.actionHandler = [[MVMCoreActionHandler alloc] init];
|
||||
self.loggingDelegate = [[MVMCoreLoggingHandler alloc] init];
|
||||
self.loadHandler = [[MVMCoreLoadHandler alloc] init];
|
||||
self.clientParameterRegistry = [[ClientParameterRegistry alloc] init];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user