Merge branch 'bugfix/async_and_warnings' into 'develop'
Bugfixes for getInitialParameters, completion block consolidation with async,... ### Summary Bugfixes for getInitialParameters, completion block consolidation with async, and minor warning fixes Co-authored-by: Scott Pfeil <Scott.Pfeil3@verizonwireless.com> See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core/-/merge_requests/278
This commit is contained in:
commit
e942bbfe15
@ -48,14 +48,14 @@
|
||||
- (void)setHeadersForRequest:(nonnull NSMutableURLRequest *)request requestParameters:(nonnull MVMCoreRequestParameters *)requestParameters;
|
||||
|
||||
// Converts the core request parameters into a JSON object dictionary.
|
||||
- (void)getJsonDictionary:(nonnull MVMCoreRequestParameters *)requestParameters closure:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))closure;
|
||||
- (void)getJsonDictionary:(nonnull MVMCoreRequestParameters *)requestParameters completion:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completion;
|
||||
|
||||
- (void)getJsonData:(nonnull MVMCoreRequestParameters *)requestParameters forUrl:(nonnull NSURL *)url closure:(nonnull void (^)(NSData * _Nullable data, MVMCoreErrorObject *_Nullable error))closure;
|
||||
- (void)getJsonData:(nonnull MVMCoreRequestParameters *)requestParameters forUrl:(nonnull NSURL *)url completion:(nonnull void (^)(NSData * _Nullable data, MVMCoreErrorObject *_Nullable error))completion;
|
||||
|
||||
- (void)getInitialParametersExcludingSections:(NSSet<NSString *> *_Nullable)excludeSections closure:(nonnull void (^)(NSDictionary *_Nullable parameters))closure;
|
||||
- (void)getInitialParametersExcludingSections:(NSSet<NSString *> *_Nullable)excludeSections completion:(nonnull void (^)(NSDictionary *_Nullable parameters))completion NS_SWIFT_NAME(initialParameters(excludingSections:completion:));
|
||||
|
||||
// Creates a request object with the given parameters.
|
||||
- (void)transformToRequestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters closure:(nonnull void (^)(NSURLRequest * _Nullable request, MVMCoreErrorObject *_Nullable error))closure;
|
||||
- (void)transformToRequestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters completion:(nonnull void (^)(NSURLRequest * _Nullable request, MVMCoreErrorObject *_Nullable error))completion;
|
||||
|
||||
// Sends a given request to the server. When it is finished, it calls request finished, passing along the json object or nil if there is an error.
|
||||
- (void)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject * _Nullable error))requestFinished;
|
||||
|
||||
@ -132,7 +132,7 @@
|
||||
|
||||
#pragma mark - Request Functions.
|
||||
|
||||
- (void)transformToRequestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters closure:(nonnull void (^)(NSURLRequest * _Nullable request, MVMCoreErrorObject *_Nullable error))closure {
|
||||
- (void)transformToRequestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters completion:(nonnull void (^)(NSURLRequest * _Nullable request, MVMCoreErrorObject *_Nullable error))completion {
|
||||
|
||||
NSURL *url = [requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]];
|
||||
|
||||
@ -152,14 +152,14 @@
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:timeOutInterval];
|
||||
[self setHeadersForRequest:request requestParameters:requestParameters];
|
||||
|
||||
[self getJsonData:requestParameters forUrl:url closure:^(NSData * _Nullable jsonData, MVMCoreErrorObject * _Nullable error) {
|
||||
[self getJsonData:requestParameters forUrl:url completion:^(NSData * _Nullable jsonData, MVMCoreErrorObject * _Nullable error) {
|
||||
/// Ensures that something in the body is always set.
|
||||
if (!jsonData) {
|
||||
closure(nil, error ?: [[MVMCoreErrorObject alloc] initWithTitle:nil message:nil code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters_%@",requestParameters.pageType]]);
|
||||
completion(nil, error ?: [[MVMCoreErrorObject alloc] initWithTitle:nil message:nil code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters_%@",requestParameters.pageType]]);
|
||||
return;
|
||||
}
|
||||
[request setHTTPBody:jsonData];
|
||||
closure(request, nil);
|
||||
completion(request, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
@ -191,9 +191,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)getInitialParametersExcludingSections:(NSSet<NSString *> *_Nullable)excludeSections closure:(nonnull void (^)(NSDictionary *_Nullable parameters))closure {}
|
||||
- (void)getInitialParametersExcludingSections:(NSSet<NSString *> *_Nullable)excludeSections completion:(nonnull void (^)(NSDictionary *_Nullable parameters))closure {}
|
||||
|
||||
- (void)getJsonDictionary:(nonnull MVMCoreRequestParameters *)requestParameters closure:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))closure {
|
||||
- (void)getJsonDictionary:(nonnull MVMCoreRequestParameters *)requestParameters completion:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completion {
|
||||
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||||
|
||||
// Adds request specific parameters
|
||||
@ -202,24 +202,24 @@
|
||||
}
|
||||
|
||||
if (!requestParameters.addInitialRequestParameters) {
|
||||
closure(parameters);
|
||||
completion(parameters);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sets up the Initial parameters.
|
||||
[self getInitialParametersExcludingSections:requestParameters.excludedInitialParameters closure:^(NSDictionary * _Nullable initialParameters) {
|
||||
[self getInitialParametersExcludingSections:requestParameters.excludedInitialParameters completion:^(NSDictionary * _Nullable initialParameters) {
|
||||
if (initialParameters) {
|
||||
[parameters setObject:initialParameters forKey:@"InitialParams"];
|
||||
}
|
||||
closure(parameters);
|
||||
completion(parameters);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getJsonData:(nonnull MVMCoreRequestParameters *)requestParameters forUrl:(nonnull NSURL *)url closure:(nonnull void (^)(NSData * _Nullable data, MVMCoreErrorObject * _Nullable error))closure {
|
||||
[self getJsonDictionary:requestParameters closure:^(NSDictionary * _Nullable parameters) {
|
||||
- (void)getJsonData:(nonnull MVMCoreRequestParameters *)requestParameters forUrl:(nonnull NSURL *)url completion:(nonnull void (^)(NSData * _Nullable data, MVMCoreErrorObject * _Nullable error))completion {
|
||||
[self getJsonDictionary:requestParameters completion:^(NSDictionary * _Nullable parameters) {
|
||||
// Ensure the parameters are valid json.
|
||||
if (![NSJSONSerialization isValidJSONObject:parameters]) {
|
||||
closure(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
completion(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@
|
||||
// Pretty print for logging the request parameters.
|
||||
data = [NSJSONSerialization dataWithJSONObject:parameters options:NSJSONWritingPrettyPrinted error:&jsonError];
|
||||
if (!data) {
|
||||
closure(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] messageToLog:jsonError.localizedDescription code:jsonError.code domain:ErrorDomainSystem location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
completion(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] messageToLog:jsonError.localizedDescription code:jsonError.code domain:ErrorDomainSystem location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
return;
|
||||
}
|
||||
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
@ -239,7 +239,7 @@
|
||||
// Standard condensed to send to the server.
|
||||
data = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&jsonError];
|
||||
if (!data) {
|
||||
closure(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] messageToLog:jsonError.localizedDescription code:jsonError.code domain:ErrorDomainSystem location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
completion(nil, [[MVMCoreErrorObject alloc] initWithTitle:nil message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] messageToLog:jsonError.localizedDescription code:jsonError.code domain:ErrorDomainSystem location:[NSString stringWithFormat:@"requestWithParameters:pageType_%@:parameters_%@",requestParameters.pageType,parameters.description]]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@
|
||||
if (requestParameters.imageData) {
|
||||
data = [self createMultipartFormBodyForRequestJsonData:data imageData:requestParameters.imageData];
|
||||
}
|
||||
closure(data, nil);
|
||||
completion(data, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@
|
||||
}
|
||||
|
||||
- (void)sendRequest:(nonnull MVMCoreRequestParameters *)requestParameters locationForError:(nonnull NSString *)locationForError requestFinished:(nullable void (^)(id _Nullable jsonObject, MVMCoreErrorObject *_Nullable error))requestFinished {
|
||||
[self transformToRequestWithParameters:requestParameters closure:^(NSURLRequest * _Nullable request, MVMCoreErrorObject * _Nullable error) {
|
||||
[self transformToRequestWithParameters:requestParameters completion:^(NSURLRequest * _Nullable request, MVMCoreErrorObject * _Nullable error) {
|
||||
if (error) {
|
||||
if (requestFinished) {
|
||||
requestFinished(nil, error);
|
||||
|
||||
@ -10,16 +10,13 @@ import Foundation
|
||||
|
||||
public extension MVMCoreLoadHandler {
|
||||
func sendRequest(with parameters: MVMCoreRequestParameters, locationForError: String, requestFinished: @escaping (Any?, MVMCoreErrorObject?) -> Void) async -> URLSessionTask? {
|
||||
return await withCheckedContinuation { continuation in
|
||||
transformToRequest(with: parameters) { request, error in
|
||||
guard let request = request else {
|
||||
defer {
|
||||
requestFinished(nil, error)
|
||||
}
|
||||
return continuation.resume(returning: nil)
|
||||
}
|
||||
continuation.resume(returning: self.send(request, requestParameters: parameters, locationForError: locationForError, requestFinished: requestFinished))
|
||||
let result = await transformToRequest(with: parameters)
|
||||
guard let request = result.0 else {
|
||||
defer {
|
||||
requestFinished(nil, result.1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return self.send(request, requestParameters: parameters, locationForError: locationForError, requestFinished: requestFinished)
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
@interface MVMCoreLoadRequestOperation ()
|
||||
|
||||
@property (weak, nonatomic) NSURLSessionTask *sessionTask;
|
||||
@property (strong, nonatomic) NSURLSessionTask *sessionTask;
|
||||
|
||||
// For temporarily storing any alert to show until we determine it's delegate.
|
||||
@property (nonatomic, readwrite) BOOL alertToShow;
|
||||
@ -304,7 +304,7 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
[[MVMCoreLoadHandler sharedGlobal] transformToRequestWithParameters:requestParameters closure:^(NSURLRequest * _Nullable request, MVMCoreErrorObject * _Nullable error) {
|
||||
[[MVMCoreLoadHandler sharedGlobal] transformToRequestWithParameters:requestParameters completion:^(NSURLRequest * _Nullable request, MVMCoreErrorObject * _Nullable error) {
|
||||
loadObject.operation.sessionTask = [[MVMCoreLoadHandler sharedGlobal] sendRequest:request requestParameters:requestParameters locationForError:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject] requestFinished:^(id jsonObject, MVMCoreErrorObject *error) {
|
||||
|
||||
if ([loadObject.operation checkAndHandleForCancellation]) {
|
||||
|
||||
@ -29,9 +29,6 @@
|
||||
/// Creates the nsurlsession with default configuration and no delegate. Can subclass for different session.
|
||||
- (nonnull NSURLSession *)createNSURLSession;
|
||||
|
||||
/// Gets inital parameters for request parameters.
|
||||
- (nullable NSDictionary *)getInitialParameters;
|
||||
|
||||
/// Restarts the application session state. Can clear variables and pass a page type if needed.
|
||||
- (void)restartSessionWithPageType:(nullable NSString *)pageType requestUrl:(nullable NSURL *)requestUrl parameters:(nullable NSDictionary *)parameters clearAllVariables:(BOOL)clearAllVariables;
|
||||
|
||||
|
||||
@ -64,15 +64,11 @@ public extension MVMCoreActionUtility {
|
||||
@objc public extension MVMCoreActionUtility {
|
||||
/// Can call to display a view controller based on the load object in the same way the architecture does it. Will check the presentation style of the page, action, and request. Will check if needs a view manager.
|
||||
@objc(displayViewController:forLoadObject:completionHandler:)
|
||||
static func display(_ viewController: UIViewController & MVMCoreViewControllerProtocol, for loadObject: MVMCoreLoadObject?, completionHandler: (() -> Void)? = nil) {
|
||||
Task(priority: .high) {
|
||||
guard let navigationOperation = await NavigationHandler.shared().getNavigationOperation(with: viewController, loadObject: loadObject) else {
|
||||
completionHandler?()
|
||||
static func display(_ viewController: UIViewController & MVMCoreViewControllerProtocol, for loadObject: MVMCoreLoadObject?) async {
|
||||
guard let navigationOperation = await NavigationHandler.shared().getNavigationOperation(with: viewController, loadObject: loadObject) else {
|
||||
return
|
||||
}
|
||||
await NavigationHandler.shared().navigate(with: navigationOperation)
|
||||
completionHandler?()
|
||||
}
|
||||
await NavigationHandler.shared().navigate(with: navigationOperation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user