diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index e3bfcbf..17f2327 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -29,6 +29,8 @@ extern NSString * _Nonnull const KeyActionTypeOpen; - (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate; #pragma mark - Actions +// by default, returns the original RequestParameter that passed in. Can be overriden for some generic updates to the RequestParameter before handle open page action gets called. +- (void)updateRequestParametersBeforeHandleOpenPageAction:(nonnull MVMCoreRequestParameters *)requestParameters callBack:(void (^_Nonnull)(MVMCoreRequestParameters * _Nonnull requestParameters))callback; // Logs the action. Currently is not action information driven... depends on delegate. - (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 86ea2d6..e6932bf 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -85,6 +85,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; #pragma mark - Actions +- (void)updateRequestParametersBeforeHandleOpenPageAction:(nonnull MVMCoreRequestParameters *)requestParameters callBack:(void (^_Nonnull)(MVMCoreRequestParameters * _Nonnull requestParameters))callback { + //does not do anything by default, can be override + callback(requestParameters); +} + - (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { if ([delegate respondsToSelector:@selector(logActionWithActionInformation:additionalData:)]) { [delegate logActionWithActionInformation:actionInformation additionalData:additionalData]; @@ -115,11 +120,14 @@ NSString * const KeyActionTypeOpen = @"openPage"; MVMCoreLog(@"Continuing operation after freebee request"); MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation]; - if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { - [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData]; - } else { - [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; - } + + [self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { + if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { + [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData]; + } else { + [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; + } + }]; } else { // No page type to load, show error. @@ -168,15 +176,18 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { // Perform the previous submission. + __weak typeof(self) weakSelf = self; if ([delegate respondsToSelector:@selector(prepareRequestForPreviousSubmission:additionalData:submit:)]) { [delegate prepareRequestForPreviousSubmission:actionInformation additionalData:additionalData submit:^(MVMCoreRequestParameters * _Nonnull requestParameters, NSDictionary * _Nullable dataForPage) { - // Give the delegate a chance to alter the request parameters - if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { - [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:dataForPage]; - } else { - [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; - } + [weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { + // Give the delegate a chance to alter the request parameters + if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { + [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:dataForPage]; + } else { + [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; + } + }]; }]; } } @@ -232,12 +243,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; NSString *type = [actionInformation string:KeyPageType]; if ([@"location" isEqualToString:type] || [@"push" isEqualToString:type]) { [MVMCoreActionUtility linkAway:UIApplicationOpenSettingsURLString appURLString:nil]; - } else if ([@"airplaneMode" isEqualToString:type]) { - - // Stopped working in iOS 10. - [MVMCoreActionUtility linkAway:@"prefs:root=AIRPLANE_MODE" appURLString:nil]; - } else { - + } else { // No known settings type MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeInvalidSettingType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeSettings]]; [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];