delegate object and simple deprecation
This commit is contained in:
parent
9b582860d2
commit
f1d884227f
@ -142,6 +142,7 @@
|
||||
AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; };
|
||||
D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; };
|
||||
D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@ -274,6 +275,7 @@
|
||||
AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = "<group>"; };
|
||||
D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = "<group>"; };
|
||||
D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = "<group>"; };
|
||||
D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateObject.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -393,6 +395,7 @@
|
||||
AF43A7191FC5BE9E008E9347 /* MainProtocols */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D2E1FAD82260C3E400AEFD8C /* DelegateObject.swift */,
|
||||
AF43A71A1FC5BEBB008E9347 /* MVMCoreViewControllerProtocol.h */,
|
||||
AF43A71F1FC5D2BA008E9347 /* MVMCoreViewManagerProtocol.h */,
|
||||
AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */,
|
||||
@ -766,6 +769,7 @@
|
||||
AFBB96641FBA3A570008D868 /* MVMCoreLoadHandler.m in Sources */,
|
||||
AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */,
|
||||
AFBB968E1FBA3A9A0008D868 /* MVMCoreNavigationHandler.m in Sources */,
|
||||
D2E1FAD92260C3E400AEFD8C /* DelegateObject.swift in Sources */,
|
||||
AFBB96991FBA3A9A0008D868 /* MVMCoreAlertController.m in Sources */,
|
||||
881D26941FCC9D180079C521 /* MVMCoreOperation.m in Sources */,
|
||||
AFED77A41FCCA29400BAE689 /* MVMCoreViewControllerMappingObject.m in Sources */,
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
|
||||
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
|
||||
#import <MVMCore/MVMCorePresentationDelegateProtocol.h>
|
||||
|
||||
@class DelegateObject;
|
||||
|
||||
extern NSString * _Nonnull const KeyActionType;
|
||||
extern NSString * _Nonnull const KeyActionTypeLinkAway;
|
||||
@ -23,83 +23,154 @@ extern NSString * _Nonnull const KeyActionTypeOpen;
|
||||
+ (nullable instancetype)sharedActionHandler;
|
||||
|
||||
// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values
|
||||
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Handles actions. Used by server driven user actions..
|
||||
- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
#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 <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Tries to open a page
|
||||
- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// restarts the app
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Goes back
|
||||
- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Makes a phone call
|
||||
- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Makes the previous request, needs the delegate for this
|
||||
- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Shows a popup
|
||||
- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Shows a top alert
|
||||
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Redirects to another experience
|
||||
- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Cancels (like in a popup)
|
||||
- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Goes to settings app
|
||||
- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Collapses the current top notification
|
||||
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Subclass this to handle other custom actions. Return YES if handled, and NO if not.
|
||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Last chance to handle unknown actions before throwing an error
|
||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Handles action errors.
|
||||
- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
#pragma mark - Link away action
|
||||
|
||||
// Links away to app or browser
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Can subclass to add to urls if needed at global level (delegate is also called)
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Opens the url
|
||||
- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// opens the url in a webview.
|
||||
- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
#pragma mark - Default Action Protocol Functions
|
||||
|
||||
// Sends the request to the load handler.
|
||||
+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// 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;
|
||||
+ (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Shows a popup error
|
||||
+ (void)defaultHandleActionError:(nonnull MVMCoreErrorObject *)error additionalData:(nullable NSDictionary *)additionalData;
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values
|
||||
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Handles actions. Used by server driven user actions..
|
||||
- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Logs the action. Currently is not action information driven... depends on delegate.
|
||||
- (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Tries to open a page
|
||||
- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// restarts the app
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Goes back
|
||||
- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Makes a phone call
|
||||
- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Makes the previous request, needs the delegate for this
|
||||
- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Shows a popup
|
||||
- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Shows a top alert
|
||||
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Redirects to another experience
|
||||
- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Cancels (like in a popup)
|
||||
- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Goes to settings app
|
||||
- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Collapses the current top notification
|
||||
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Subclass this to handle other custom actions. Return YES if handled, and NO if not.
|
||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Last chance to handle unknown actions before throwing an error
|
||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Handles action errors.
|
||||
- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Links away to app or browser
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Can subclass to add to urls if needed at global level (delegate is also called)
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Opens the url
|
||||
- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// opens the url in a webview.
|
||||
- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Sends the request to the load handler.
|
||||
+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// 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;
|
||||
|
||||
@end
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#import "MVMCoreObject.h"
|
||||
#import "MVMCorePresentationDelegateProtocol.h"
|
||||
#import <SafariServices/SafariServices.h>
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
NSString * const KeyActionType = @"actionType";
|
||||
NSString * const KeyActionTypeLinkAway = @"openURL";
|
||||
@ -39,6 +40,352 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
return [MVMCoreActionUtility initializerClassCheck:[MVMCoreObject sharedInstance].actionHandler classToVerify:self];
|
||||
}
|
||||
|
||||
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
NSString *action = [dictionary stringForKey:KeyActionType];
|
||||
[self handleAction:action actionInformation:dictionary additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
|
||||
- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
||||
// Logs the action.
|
||||
[self logAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
|
||||
if ([actionType isEqualToString:KeyActionTypeOpen]) {
|
||||
[self openPageAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeLinkAway]) {
|
||||
[self linkAwayAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeRestart]) {
|
||||
[self restartAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeBack]) {
|
||||
[self backAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeCall]) {
|
||||
[self callAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) {
|
||||
[self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypePopup]) {
|
||||
[self popupAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeTopAlert]) {
|
||||
[self topAlertAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeRedirect]) {
|
||||
[self redirectAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeCancel]) {
|
||||
[self cancelAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeSettings]) {
|
||||
[self settingsAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if ([actionType isEqualToString:KeyActionTypeCollapseNotification]) {
|
||||
[self collapseNotificationAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) {
|
||||
// not a known action type.
|
||||
[self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#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 delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(logActionWithActionInformation:additionalData:)]) {
|
||||
[delegateObject.actionDelegate logActionWithActionInformation:actionInformation additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultLogAction:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Loads the given page type.
|
||||
NSString *pageType = [actionInformation stringForKey:KeyPageType];
|
||||
if (pageType.length > 0) {
|
||||
|
||||
//if freebee enabled for account,and state isNotDetermined or is expired
|
||||
//launchFreebee auth request
|
||||
//else if invalid or valid or busy do nothing
|
||||
#warning i'd like to move this out of here.
|
||||
MFFreebeeHandler *freebeeHandler = [MFFreebeeHandler sharedHandler];
|
||||
if (YES == [freebeeHandler canProceedWithFreebeeAuthRequest]) {
|
||||
|
||||
MVMCoreLog(@"Processing Freebee Auth request");
|
||||
[freebeeHandler processFreeBeeAuthRequestWithCompletionHandler:^(MVMCoreOperation* _Nullable freebeeOperation, BOOL isValid) {
|
||||
|
||||
MVMCoreLog(@"Processing Freebee Auth request Initiated");
|
||||
}];
|
||||
}
|
||||
|
||||
MVMCoreLog(@"Continuing operation after freebee request");
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation];
|
||||
|
||||
[self 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];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Invalidates the session before restarting.
|
||||
[[MVMCoreSessionTimeHandler sharedSessionHandler] invalidateSession:^(MVMCoreErrorObject * _Nullable error) {
|
||||
|
||||
// Restarts the app (forcing any passed in page types).
|
||||
if (error.code != NSURLErrorCancelled) {
|
||||
|
||||
if (error) {
|
||||
|
||||
// Error invalidating.
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else {
|
||||
|
||||
// Restart the application with the page type.
|
||||
NSString *pageType = [actionInformation string:KeyPageType];
|
||||
NSDictionary *parameters = [actionInformation dict:KeyExtraParameters];
|
||||
[[MVMCoreSessionObject sharedGlobal] restartSessionWithPageType:pageType parameters:parameters clearAllVariables:YES];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Go back.
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleBackAction:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleBackAction:actionInformation additionalData:additionalData];
|
||||
} else {
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Call
|
||||
NSString *callNumber = [actionInformation stringForKey:KeyCallNumber];
|
||||
[MVMCoreActionUtility linkAway:[@"tel://" stringByAppendingString:callNumber] appURLString:nil];
|
||||
}
|
||||
|
||||
- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Perform the previous submission.
|
||||
__weak typeof(self) weakSelf = self;
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(prepareRequestForPreviousSubmission:additionalData:submit:)]) {
|
||||
[delegateObject.actionDelegate prepareRequestForPreviousSubmission:actionInformation additionalData:additionalData submit:^(MVMCoreRequestParameters * _Nonnull requestParameters, NSDictionary * _Nullable dataForPage) {
|
||||
|
||||
[weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
// Give the delegate a chance to alter the request parameters
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:dataForPage];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)popupAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Perform a popup.
|
||||
NSString *pageTypeForPopup = [actionInformation stringForKey:KeyPageType];
|
||||
[[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForPopup queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||
|
||||
MVMCoreErrorObject *error = nil;
|
||||
MVMCoreAlertObject *alertObject = [MVMCoreAlertObject alertObjectWithPage:jsonDictionary isGreedy:NO additionalData:additionalData delegateObject:delegateObject error:&error];
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(willShowPopupWithAlertObject:alertJson:)]) {
|
||||
[delegateObject.actionDelegate willShowPopupWithAlertObject:alertObject alertJson:jsonDictionary];
|
||||
}
|
||||
|
||||
if (alertObject) {
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject];
|
||||
} else {
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject ];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Perform a top alert.
|
||||
NSString *pageTypeForTopAlert = [actionInformation stringForKey:KeyPageType];
|
||||
[[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||
|
||||
NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo];
|
||||
if (responseInfo) {
|
||||
MVMCoreAlertObject *alertObject = [MVMCoreAlertObject alertObjectForPageType:pageTypeForTopAlert responseInfo:responseInfo additionalData:additionalData delegateObject:delegateObject];
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(willShowTopAlertWithAlertObject:alertJson:)]) {
|
||||
alertObject = [delegateObject.actionDelegate willShowTopAlertWithAlertObject:alertObject alertJson:jsonDictionary];
|
||||
}
|
||||
[alertObject showAlert];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Have delegate redirect.
|
||||
[[MVMCoreSessionObject sharedGlobal] redirectWithInfo:actionInformation];
|
||||
}
|
||||
|
||||
- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleCancel:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleCancel:actionInformation additionalData:additionalData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Opens the settings.
|
||||
NSString *type = [actionInformation string:KeyPageType];
|
||||
if ([@"location" isEqualToString:type] || [@"push" isEqualToString:type]) {
|
||||
[MVMCoreActionUtility linkAway:UIApplicationOpenSettingsURLString appURLString:nil];
|
||||
} 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([delegateObject.actionDelegate class]),KeyActionTypeSettings]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
// Collapse the current notification.
|
||||
if ([[MVMCoreObject sharedInstance].globalTopAlertDelegate respondsToSelector:@selector(getTopAlertView)]) {
|
||||
[[[MVMCoreObject sharedInstance].globalTopAlertDelegate getTopAlertView] collapseNotification];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleUnknownActionType:actionInformation:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleUnknownActionType:actionType actionInformation:actionInformation additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleUnknownActionType:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if (error) {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleActionError:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleActionError:error additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleActionError:error additionalData:additionalData];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
void(^openURL)(NSURL *, NSURL *, NSDictionary *, NSDictionary *) = ^(NSURL *appURL, NSURL *URL, NSDictionary *actionInformation, NSDictionary *additionalData) {
|
||||
[self openURL:url appURL:appURL actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
};
|
||||
|
||||
// Allow delegate to modify before opening the url.
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(shouldLinkAwayWithURL:appURL:actionInformation:additionalData:linkAwayBlock:)]) {
|
||||
[delegateObject.actionDelegate shouldLinkAwayWithURL:url appURL:appURL actionInformation:actionInformation additionalData:additionalData linkAwayBlock:openURL];
|
||||
} else {
|
||||
openURL(appURL,url,actionInformation,additionalData);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
[MVMCoreDispatchUtility performBlockOnMainThread:^{
|
||||
|
||||
// First try to open the application.
|
||||
if (appURL && [[UIApplication sharedApplication] canOpenURL:appURL]) {
|
||||
[[UIApplication sharedApplication] openURL:appURL options:@{} completionHandler:NULL];
|
||||
} else if (url && [[UIApplication sharedApplication] canOpenURL:url]) {
|
||||
|
||||
// Check if we should load in webview
|
||||
BOOL openInWebview = [actionInformation boolForKey:@"openInWebview"];
|
||||
if (openInWebview) {
|
||||
[self openURLInWebView:url actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
} else {
|
||||
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];
|
||||
}
|
||||
} else {
|
||||
[MVMCoreDispatchUtility performBlockInBackground:^{
|
||||
// Cannot linkaway, show error.
|
||||
MVMCoreErrorObject *error = error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeLinkawayFailed domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeLinkAway]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Presents standard webview.
|
||||
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url];
|
||||
//safariViewController.delegate = self;
|
||||
safariViewController.preferredBarTintColor = [UIColor whiteColor];
|
||||
safariViewController.preferredControlTintColor = [UIColor blackColor];
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Default Action Protocol Functions
|
||||
|
||||
+ (void)defaultLogAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject{
|
||||
// Currently no default log action but this will eventually be server driven.
|
||||
}
|
||||
|
||||
+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
[[MVMCoreLoadHandler sharedGlobal] loadRequest:requestParameters dataForPage:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
|
||||
+ (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeUnknownActionType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@Requests_%@",NSStringFromClass([delegateObject.actionDelegate class]),actionType]];
|
||||
[MVMCoreActionHandler defaultHandleActionError:error additionalData:additionalData];
|
||||
}
|
||||
|
||||
+ (void)defaultHandleActionError:(nonnull MVMCoreErrorObject *)error additionalData:(nullable NSDictionary *)additionalData {
|
||||
|
||||
// Logs the error.
|
||||
if (error.logError) {
|
||||
[MVMCoreLoggingHandler addErrorToLog:error];
|
||||
}
|
||||
|
||||
MVMCoreLog(@"Error: %@ %@ %@ %@",[error stringErrorCode], error.domain, error.location,error.messageToDisplay);
|
||||
if (!error.silentError) {
|
||||
|
||||
// Show alert
|
||||
MVMCoreAlertObject *alertObject = [[MVMCoreAlertObject alloc] initPopupAlertWithError:error isGreedy:NO];
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
NSString *action = [dictionary stringForKey:KeyActionType];
|
||||
@ -46,7 +393,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
|
||||
- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
||||
// Logs the action.
|
||||
@ -83,13 +430,6 @@ 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 <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
if ([delegate respondsToSelector:@selector(logActionWithActionInformation:additionalData:)]) {
|
||||
[delegate logActionWithActionInformation:actionInformation additionalData:additionalData];
|
||||
@ -243,7 +583,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
NSString *type = [actionInformation string:KeyPageType];
|
||||
if ([@"location" isEqualToString:type] || [@"push" isEqualToString:type]) {
|
||||
[MVMCoreActionUtility linkAway:UIApplicationOpenSettingsURLString 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];
|
||||
@ -279,8 +619,6 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - open url functions
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
// Gets the app url
|
||||
@ -351,8 +689,6 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
[[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Default Action Protocol Functions
|
||||
|
||||
+ (void)defaultLogAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate{
|
||||
// Currently no default log action but this will eventually be server driven.
|
||||
}
|
||||
@ -367,20 +703,4 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
[MVMCoreActionHandler defaultHandleActionError:error additionalData:additionalData];
|
||||
}
|
||||
|
||||
+ (void)defaultHandleActionError:(nonnull MVMCoreErrorObject *)error additionalData:(nullable NSDictionary *)additionalData {
|
||||
|
||||
// Logs the error.
|
||||
if (error.logError) {
|
||||
[MVMCoreLoggingHandler addErrorToLog:error];
|
||||
}
|
||||
|
||||
MVMCoreLog(@"Error: %@ %@ %@ %@",[error stringErrorCode], error.domain, error.location,error.messageToDisplay);
|
||||
if (!error.silentError) {
|
||||
|
||||
// Show alert
|
||||
MVMCoreAlertObject *alertObject = [[MVMCoreAlertObject alloc] initPopupAlertWithError:error isGreedy:NO];
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:alertObject];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
|
||||
#import <MVMCore/MVMCoreTopAlertObject.h>
|
||||
#import <MVMCore/MVMCoreAlertDelegateProtocol.h>
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
@class MVMCoreErrorObject;
|
||||
@class MVMCoreLoadObject;
|
||||
@class DelegateObject;
|
||||
|
||||
typedef NS_ENUM(NSInteger, MFAlertType) {
|
||||
MFAlertTypePopup = 0,
|
||||
@ -43,8 +44,8 @@ typedef void (^TextFieldErrorHandler)(NSArray * _Nonnull fieldErrors);
|
||||
@property (nonatomic, weak, nullable) NSObject <MVMCoreAlertDelegateProtocol> *alertDelegate;
|
||||
|
||||
// Creates an alert object for an error with the passed in load object response info
|
||||
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate;
|
||||
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate;
|
||||
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Initializes a popup style alert object. Look at the alert handler to see what each is used for.
|
||||
- (nullable instancetype)initPopupAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy;
|
||||
@ -56,9 +57,16 @@ typedef void (^TextFieldErrorHandler)(NSArray * _Nonnull fieldErrors);
|
||||
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy;
|
||||
|
||||
// Returns the alert object made with the page json. If there is not enough data to make, we will set error
|
||||
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error;
|
||||
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error;
|
||||
|
||||
// Will show this alert in it's appropriate type style.
|
||||
- (void)showAlert;
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
// Creates an alert object for an error with the passed in load object response info
|
||||
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate __deprecated;
|
||||
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate __deprecated;
|
||||
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error __deprecated;
|
||||
|
||||
@end
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#import "MVMCoreHardcodedStringsConstants.h"
|
||||
#import "MVMCoreJSONConstants.h"
|
||||
#import <MVMCore/MVMCoreActionHandler.h>
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
@interface MVMCoreAlertObject ()
|
||||
|
||||
@ -28,6 +29,168 @@
|
||||
|
||||
@implementation MVMCoreAlertObject
|
||||
|
||||
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
MVMCoreAlertObject *alert = nil;
|
||||
if (!error || [ErrorDomainServer isEqualToString:error.domain]) {
|
||||
alert = [MVMCoreAlertObject alertObjectForPageType:loadObject.pageType responseInfo:loadObject.responseInfoMap additionalData:loadObject.dataForPage delegateObject:delegateObject];
|
||||
} else {
|
||||
alert = [[MVMCoreAlertObject alloc] initPopupAlertWithError:error isGreedy:NO];
|
||||
}
|
||||
|
||||
// only if actions are empty, then go inside and set OK as default action
|
||||
if (alert.type == MFAlertTypePopup && alert.actions.count == 0) {
|
||||
alert.defaultAction = YES;
|
||||
alert.actions = @[[UIAlertAction actionWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedOK] style:UIAlertActionStyleDefault handler:nil]];
|
||||
}
|
||||
return alert;
|
||||
}
|
||||
|
||||
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
__block MVMCoreAlertObject *alert = [[MVMCoreAlertObject alloc] init];
|
||||
alert.title = [responseInfo stringForKey:KeyErrorHeading];
|
||||
alert.message = [responseInfo stringForKey:KeyUserMessage];
|
||||
|
||||
NSString *messageStyle = [responseInfo stringForKey:KeyMessageStyle];
|
||||
if ([ValueTypeFieldErrors isEqualToString:[responseInfo string:KeyType]]) {
|
||||
|
||||
// field errors.
|
||||
alert.type = MFAlertTypeField;
|
||||
alert.fieldErrors = [responseInfo array:ValueTypeFieldErrors];
|
||||
} else {
|
||||
|
||||
// Check for top alert (persistent or regular).
|
||||
if ([messageStyle isEqualToString:ValueMessageStyleTopPersistent] || [messageStyle isEqualToString:ValueMessageStyleTop]) {
|
||||
|
||||
alert.topAlertObject = [[MVMCoreTopAlertObject alloc] initWithResponseInfo:responseInfo];
|
||||
alert.topAlertObject.delegate = delegateObject.topAlertDelegate;
|
||||
alert.topAlertObject.pageType = pageType;
|
||||
alert.type = MFAlertTypeTop;
|
||||
} else if ([messageStyle isEqualToString:ValueMessageStylePopup]) {
|
||||
|
||||
// Perform a popup.
|
||||
alert.type = MFAlertTypePopup;
|
||||
alert.alertStyle = UIAlertControllerStyleAlert;
|
||||
|
||||
// Check if we have a popup driven by page object (otherwise by default it will just use response info title message with an OK button).
|
||||
NSString *pageTypeForPopup = [responseInfo stringForKey:@"popupPageType"];
|
||||
[[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForPopup queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||
|
||||
MVMCoreErrorObject *error = nil;
|
||||
MVMCoreAlertObject *popupAlert = [MVMCoreAlertObject alertObjectWithPage:jsonDictionary isGreedy:NO additionalData:additionalData delegateObject:delegateObject error:&error];
|
||||
if (error) {
|
||||
|
||||
// Error, popup page not found for page type.
|
||||
popupAlert = [[MVMCoreAlertObject alloc] initPopupAlertWithError:error isGreedy:NO];
|
||||
}
|
||||
|
||||
if (popupAlert) {
|
||||
alert = popupAlert;
|
||||
}
|
||||
}];
|
||||
} else if (messageStyle.length == 0 && pageType) {
|
||||
|
||||
// No message style!
|
||||
alert.type = MFAlertTypeNone;
|
||||
} else {
|
||||
|
||||
// Default to popup
|
||||
alert.type = MFAlertTypePopup;
|
||||
alert.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
}
|
||||
alert.alertDelegate = delegateObject.alertDelegate;
|
||||
return alert;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy {
|
||||
if (self = [super init]) {
|
||||
self.title = title;
|
||||
self.message = message;
|
||||
self.actions = actions;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error isGreedy:(BOOL)isGreedy {
|
||||
|
||||
if (self = [super init]) {
|
||||
self.title = error.title;
|
||||
self.message = [NSString stringWithFormat:@"%@ (%@)",error.messageToDisplay,[error stringErrorCode]];
|
||||
self.actions = @[[UIAlertAction actionWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedOK] style:UIAlertActionStyleDefault handler:nil]];
|
||||
self.defaultAction = YES;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy {
|
||||
|
||||
if (self = [super init]) {
|
||||
self.title = error.title;
|
||||
self.message = [NSString stringWithFormat:@"%@ (%@)",error.messageToDisplay,[error stringErrorCode]];
|
||||
self.actions = actions;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error {
|
||||
|
||||
MVMCoreAlertObject *alert = [[MVMCoreAlertObject alloc] init];
|
||||
alert.title = [page stringForKey:KeyTitle];
|
||||
alert.pageJson = page;
|
||||
alert.message = [page stringForKey:KeyMessage];
|
||||
alert.isGreedy = isGreedy;
|
||||
alert.type = MFAlertTypePopup;
|
||||
alert.alertStyle = UIAlertControllerStyleAlert;
|
||||
|
||||
NSArray <NSDictionary *> *actions = [page array:KeyLinks];
|
||||
NSMutableArray <UIAlertAction *> *actionsForAlert = [NSMutableArray array];
|
||||
for (NSDictionary *actionMap in actions) {
|
||||
[actionsForAlert addObject:[UIAlertAction actionWithTitle:[actionMap stringForKey:KeyTitle] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||||
[[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:actionMap additionalData:additionalData delegateObject:delegateObject];
|
||||
}]];
|
||||
}
|
||||
alert.actions = actionsForAlert;
|
||||
|
||||
if ((alert.title.length > 0 || alert.message.length > 0) && alert.actions.count > 0) {
|
||||
return alert;
|
||||
} else {
|
||||
if (error) {
|
||||
*error = [[MVMCoreErrorObject alloc] initWithTitle:nil messageToLog:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodePopupFailed domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_Popup_pageType:%@",NSStringFromClass([delegateObject.alertDelegate class]),[page stringForKey:KeyPageType]]];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showAlert {
|
||||
|
||||
switch (self.type) {
|
||||
case MFAlertTypeField:
|
||||
self.textFieldErrorHandler(self.fieldErrors);
|
||||
break;
|
||||
case MFAlertTypeTop:
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showTopAlertWithObject:self.topAlertObject];
|
||||
break;
|
||||
case MFAlertTypePopup:
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:self];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate {
|
||||
|
||||
MVMCoreAlertObject *alert = nil;
|
||||
@ -58,10 +221,10 @@
|
||||
alert.type = MFAlertTypeField;
|
||||
alert.fieldErrors = [responseInfo array:ValueTypeFieldErrors];
|
||||
} else {
|
||||
|
||||
|
||||
// Check for top alert (persistent or regular).
|
||||
if ([messageStyle isEqualToString:ValueMessageStyleTopPersistent] || [messageStyle isEqualToString:ValueMessageStyleTop]) {
|
||||
|
||||
|
||||
alert.topAlertObject = [[MVMCoreTopAlertObject alloc] initWithResponseInfo:responseInfo];
|
||||
if ([actionDelegate conformsToProtocol:@protocol(MVMCoreTopAlertDelegateProtocol)]) {
|
||||
alert.topAlertObject.delegate = (NSObject <MVMCoreTopAlertDelegateProtocol> *)actionDelegate;
|
||||
@ -107,45 +270,6 @@
|
||||
return alert;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy {
|
||||
if (self = [super init]) {
|
||||
self.title = title;
|
||||
self.message = message;
|
||||
self.actions = actions;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error isGreedy:(BOOL)isGreedy {
|
||||
|
||||
if (self = [super init]) {
|
||||
self.title = error.title;
|
||||
self.message = [NSString stringWithFormat:@"%@ (%@)",error.messageToDisplay,[error stringErrorCode]];
|
||||
self.actions = @[[UIAlertAction actionWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedOK] style:UIAlertActionStyleDefault handler:nil]];
|
||||
self.defaultAction = YES;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy {
|
||||
|
||||
if (self = [super init]) {
|
||||
self.title = error.title;
|
||||
self.message = [NSString stringWithFormat:@"%@ (%@)",error.messageToDisplay,[error stringErrorCode]];
|
||||
self.actions = actions;
|
||||
self.isGreedy = isGreedy;
|
||||
self.type = MFAlertTypePopup;
|
||||
self.alertStyle = UIAlertControllerStyleAlert;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error {
|
||||
|
||||
MVMCoreAlertObject *alert = [[MVMCoreAlertObject alloc] init];
|
||||
@ -155,7 +279,7 @@
|
||||
alert.isGreedy = isGreedy;
|
||||
alert.type = MFAlertTypePopup;
|
||||
alert.alertStyle = UIAlertControllerStyleAlert;
|
||||
|
||||
|
||||
NSArray <NSDictionary *> *actions = [page array:KeyLinks];
|
||||
NSMutableArray <UIAlertAction *> *actionsForAlert = [NSMutableArray array];
|
||||
for (NSDictionary *actionMap in actions) {
|
||||
@ -164,7 +288,7 @@
|
||||
}]];
|
||||
}
|
||||
alert.actions = actionsForAlert;
|
||||
|
||||
|
||||
if ((alert.title.length > 0 || alert.message.length > 0) && alert.actions.count > 0) {
|
||||
return alert;
|
||||
} else {
|
||||
@ -175,21 +299,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showAlert {
|
||||
|
||||
switch (self.type) {
|
||||
case MFAlertTypeField:
|
||||
self.textFieldErrorHandler(self.fieldErrors);
|
||||
break;
|
||||
case MFAlertTypeTop:
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showTopAlertWithObject:self.topAlertObject];
|
||||
break;
|
||||
case MFAlertTypePopup:
|
||||
[[MVMCoreAlertHandler sharedAlertHandler] showAlertWithAlertObject:self];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <MVMCore/MVMCoreLoadingViewControllerProtocol.h>
|
||||
|
||||
@protocol MVMCoreLoadingOverlayDelegateProtocol <NSObject>
|
||||
@protocol MVMCoreLoadingOverlayDelegateProtocol <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
@class MVMCoreErrorObject;
|
||||
@class MVMCoreLoadObject;
|
||||
@class MVMCoreLoadRequestOperation;
|
||||
@class DelegateObject;
|
||||
|
||||
@interface MVMCoreLoadHandler : NSObject
|
||||
|
||||
@ -43,10 +44,10 @@
|
||||
#pragma mark - Loading Functions
|
||||
|
||||
// Loads a blocking request with the passed in parameters and data for the next page. Pass in the data to handle certain functions.
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Loads a background request with the passed in parameters and data for the next page. Pass in the data to handle certain functions.
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
// Loads a blocking request with the passed in load object and data for the next page.
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadObject:(nonnull MVMCoreLoadObject *)loadObject;
|
||||
@ -62,4 +63,12 @@
|
||||
// By default, returns continue loading and decides not to throw an error.
|
||||
+ (BOOL)defaultHandleModuleError:(nonnull NSString *)module loadObject:(nonnull MVMCoreLoadObject *)loadObject error:(nonnull MVMCoreErrorObject *)error;
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
// Loads a blocking request with the passed in parameters and data for the next page. Pass in the data to handle certain functions.
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
// Loads a background request with the passed in parameters and data for the next page. Pass in the data to handle certain functions.
|
||||
- (nonnull MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
@end
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#import "MVMCoreHardcodedStringsConstants.h"
|
||||
#import "MVMCoreObject.h"
|
||||
#import "MVMCoreConstants.h"
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
@interface MVMCoreLoadHandler ()
|
||||
|
||||
@ -104,7 +105,7 @@
|
||||
|
||||
- (nonnull NSString *)errorLocationForRequest:(nonnull MVMCoreLoadObject *)loadObject {
|
||||
|
||||
return [self errorLocationForRequest:loadObject.delegate 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 {
|
||||
@ -404,22 +405,19 @@
|
||||
|
||||
#pragma mark - Loading Functions
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate backgroundLoad:NO];
|
||||
- (MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject backgroundLoad:NO];
|
||||
[self.blockingLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate backgroundLoad:YES];
|
||||
- (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];
|
||||
[self.backgroundLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadObject:(nonnull MVMCoreLoadObject *)loadObject {
|
||||
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithLoadObject:loadObject backgroundLoad:NO];
|
||||
[self.blockingLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
@ -449,4 +447,20 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate backgroundLoad:NO];
|
||||
[self.blockingLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadBackgroundRequest:(nonnull MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate backgroundLoad:YES];
|
||||
[self.backgroundLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
|
||||
@class MVMCoreLoadRequestOperation;
|
||||
@class MVMCoreRequestParameters;
|
||||
@class DelegateObject;
|
||||
|
||||
@interface MVMCoreLoadObject : NSObject
|
||||
|
||||
@ -42,7 +43,8 @@
|
||||
@property (nullable, strong, nonatomic) NSDictionary *dataForPage;
|
||||
|
||||
// The load delegate
|
||||
@property (nullable, weak, nonatomic) NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *delegate;
|
||||
@property (nullable, weak, nonatomic) NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *delegate __deprecated;
|
||||
@property (nullable, weak, nonatomic) DelegateObject *delegateObject;
|
||||
|
||||
// The operation that is loading.
|
||||
@property (nullable, weak, nonatomic) MVMCoreLoadRequestOperation *operation;
|
||||
@ -51,15 +53,23 @@
|
||||
@property (nonatomic) BOOL pageDataFromCache;
|
||||
@property (nonatomic) BOOL moduleDataFromCache;
|
||||
|
||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (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 delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
- (nullable instancetype)initWithDelegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate;
|
||||
- (nullable instancetype)initWithDelegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON errorObject:(nullable MVMCoreErrorObject *)errorObject;
|
||||
|
||||
// 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<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
- (nullable instancetype)initWithDelegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate __deprecated;
|
||||
|
||||
@end
|
||||
|
||||
@ -10,12 +10,13 @@
|
||||
#import "MVMCoreErrorObject.h"
|
||||
#import "MVMCoreJSONConstants.h"
|
||||
#import "NSDictionary+MFConvenience.h"
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
@implementation MVMCoreLoadObject
|
||||
|
||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
if (self = [self initWithRequestParameters:requestParameters dataForPage:dataForPage delegate:delegate]) {
|
||||
if (self = [self initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject]) {
|
||||
self.pageJSON = pageJSON;
|
||||
self.modulesJSON = modulesJSON;
|
||||
}
|
||||
@ -26,23 +27,23 @@
|
||||
return [self.pageJSON dict:KeyButtonMap];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
if (self = [self initWithDelegate:delegate]) {
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if (self = [self initWithDelegateObject:delegateObject]) {
|
||||
self.requestParameters = requestParameters;
|
||||
self.dataForPage = dataForPage;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithDelegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
- (nullable instancetype)initWithDelegateObject:(nullable DelegateObject *)delegateObject {
|
||||
if (self = [super init]) {
|
||||
self.delegate = delegate;
|
||||
self.delegateObject = delegateObject;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON errorObject:(nullable MVMCoreErrorObject *)errorObject {
|
||||
if (self = [self initWithPageJSON:pageJSON modulesJSON:nil requestParameters:nil dataForPage:nil delegate:nil]) {
|
||||
if (self = [self initWithPageJSON:pageJSON modulesJSON:nil requestParameters:nil dataForPage:nil delegateObject:nil]) {
|
||||
|
||||
NSMutableDictionary *responseInfo = [NSMutableDictionary dictionary];
|
||||
if (errorObject.code) {
|
||||
@ -64,4 +65,40 @@
|
||||
return !extendSessionFlag || [extendSessionFlag boolValue]; // Default to YES if the key does not exist.
|
||||
}
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
- (void)setDelegateObject:(DelegateObject *)delegateObject {
|
||||
_delegateObject = delegateObject;
|
||||
_delegate = delegateObject.loadDelegate;
|
||||
}
|
||||
|
||||
- (void)setDelegate:(NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *)delegate {
|
||||
_delegate = delegate;
|
||||
_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<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)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<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
if (self = [self initWithDelegate:delegate]) {
|
||||
self.requestParameters = requestParameters;
|
||||
self.dataForPage = dataForPage;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithDelegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
if (self = [super init]) {
|
||||
self.delegate = delegate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -14,18 +14,20 @@
|
||||
|
||||
@class MVMCoreRequestParameters;
|
||||
@class MVMCoreLoadObject;
|
||||
@class DelegateObject;
|
||||
|
||||
@interface MVMCoreLoadRequestOperation : MVMCoreOperation <MVMCorePresentationDelegateProtocol>
|
||||
|
||||
@property (nullable, strong, nonatomic) MVMCoreRequestParameters *requestParameters;
|
||||
@property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject;
|
||||
@property (nullable, strong, nonatomic) NSDictionary *dataForPage;
|
||||
@property (nullable, strong, nonatomic) NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *delegate;
|
||||
@property (nullable, strong, nonatomic) NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *delegate;// __deprecated;
|
||||
@property (nullable, strong, nonatomic) DelegateObject *delegateObject;
|
||||
@property (nonatomic) BOOL backgroundLoad;
|
||||
@property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded;
|
||||
|
||||
// Initializes the operation with the request parameters object, data for page, and mvm view controller to handle the loading with.
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate backgroundLoad:(BOOL)backgroundLoad;
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject backgroundLoad:(BOOL)backgroundLoad;
|
||||
|
||||
// Initializes the operation with the load object, data for page, and mvm view controller to handle the loading with. Can be used for loading a screen without going to the cache or server.
|
||||
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad;
|
||||
@ -90,7 +92,7 @@
|
||||
+ (void)handleError:(nonnull MVMCoreErrorObject *)error loadObject:(nonnull MVMCoreLoadObject *)loadObject showAlertForErrorIfApplicable:(BOOL)showAlertForErrorIfApplicable;
|
||||
|
||||
// Shows the appropriate alert tyle for the given response info and/or error.
|
||||
+ (void)createAndShowAlertForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nonnull id)actionDelegate;
|
||||
+ (void)createAndShowAlertForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error delegateObject:(nullable DelegateObject *)delegateObject;
|
||||
|
||||
/** Called when the load was finished due to an error. Handles the error and ends the load.
|
||||
* @param error The error that occured. May be logged depending.
|
||||
@ -103,4 +105,8 @@
|
||||
* @param loadObject The load data **/
|
||||
+ (void)loadFinished:(nonnull MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController <MVMCoreViewControllerProtocol> *)loadedViewController errorObject:(nullable MVMCoreErrorObject *)errorObject;
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate backgroundLoad:(BOOL)backgroundLoad __deprecated;
|
||||
|
||||
@end
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#import <MVMCore/MVMCoreActionHandler.h>
|
||||
#import "MVMCoreObject.h"
|
||||
#import "MVMCoreConstants.h"
|
||||
#import <MVMCore/MVMCore-Swift.h>
|
||||
|
||||
@interface MVMCoreLoadRequestOperation ()
|
||||
|
||||
@ -44,11 +45,11 @@
|
||||
|
||||
#pragma mark - Initializers
|
||||
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate backgroundLoad:(BOOL)backgroundLoad {
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject backgroundLoad:(BOOL)backgroundLoad {
|
||||
if (self = [super init]) {
|
||||
self.requestParameters = requestParameters;
|
||||
self.dataForPage = dataForPage;
|
||||
self.delegate = delegate;
|
||||
self.delegateObject = delegateObject;
|
||||
self.backgroundLoad = backgroundLoad;
|
||||
}
|
||||
return self;
|
||||
@ -56,7 +57,7 @@
|
||||
|
||||
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad {
|
||||
|
||||
if (self = [self initWithRequestParameters:loadObject.requestParameters dataForPage:loadObject.dataForPage delegate:loadObject.delegate backgroundLoad:backgroundLoad]) {
|
||||
if (self = [self initWithRequestParameters:loadObject.requestParameters dataForPage:loadObject.dataForPage delegateObject:loadObject.delegateObject backgroundLoad:backgroundLoad]) {
|
||||
self.loadObject = loadObject;
|
||||
}
|
||||
return self;
|
||||
@ -92,22 +93,22 @@
|
||||
|
||||
- (BOOL)checkAndHandleForCancellation {
|
||||
|
||||
if ([self isCancelled] && [self.delegate respondsToSelector:@selector(loadCancelled:)]) {
|
||||
if ([self isCancelled] && [self.delegateObject.loadDelegate respondsToSelector:@selector(loadCancelled:)]) {
|
||||
|
||||
MVMCoreLoadObject *loadObject = self.loadObject;
|
||||
if (!loadObject) {
|
||||
loadObject = [[MVMCoreLoadObject alloc] initWithPageJSON:nil modulesJSON:nil requestParameters:self.requestParameters dataForPage:self.dataForPage delegate:self.delegate];
|
||||
loadObject = [[MVMCoreLoadObject alloc] initWithPageJSON:nil modulesJSON:nil requestParameters:self.requestParameters dataForPage:self.dataForPage delegateObject:self.delegateObject];
|
||||
loadObject.operation = self;
|
||||
}
|
||||
|
||||
// Must let the delegate know if cancelled.
|
||||
[loadObject.delegate loadCancelled:loadObject];
|
||||
[loadObject.delegateObject.loadDelegate loadCancelled:loadObject];
|
||||
}
|
||||
return [super checkAndHandleForCancellation];
|
||||
}
|
||||
|
||||
- (void)main {
|
||||
MVMCoreLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegate);
|
||||
MVMCoreLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegateObject.loadDelegate);
|
||||
|
||||
// Always check for cancellation before launching the task.
|
||||
if ([self checkAndHandleForCancellation]) {
|
||||
@ -117,7 +118,7 @@
|
||||
if (!self.requestParameters) {
|
||||
|
||||
// No load requested, finish.
|
||||
MVMCoreLoadObject *loadObject = [[MVMCoreLoadObject alloc] initWithRequestParameters:nil dataForPage:self.dataForPage delegate:self.delegate];
|
||||
MVMCoreLoadObject *loadObject = [[MVMCoreLoadObject alloc] initWithRequestParameters:nil dataForPage:self.dataForPage delegateObject:self.delegateObject];
|
||||
loadObject.operation = self;
|
||||
[MVMCoreLoadRequestOperation loadFinished:loadObject loadedViewController:nil errorObject:nil];
|
||||
} else if (self.loadObject) {
|
||||
@ -221,7 +222,7 @@
|
||||
|
||||
- (nonnull MVMCoreLoadObject *)createLoadObjectWithPageFromCache:(nullable NSDictionary *)pageFromCache modulesFromCache:(nullable NSDictionary *)modulesFromCache {
|
||||
|
||||
MVMCoreLoadObject *loadObject = [[MVMCoreLoadObject alloc] initWithPageJSON:pageFromCache modulesJSON:modulesFromCache requestParameters:self.requestParameters dataForPage:self.dataForPage delegate:self.delegate];
|
||||
MVMCoreLoadObject *loadObject = [[MVMCoreLoadObject alloc] initWithPageJSON:pageFromCache modulesJSON:modulesFromCache requestParameters:self.requestParameters dataForPage:self.dataForPage delegateObject:self.delegateObject];
|
||||
loadObject.operation = self;
|
||||
|
||||
// If we successfully grab from the cache, then the response page type is the requesting page type.
|
||||
@ -575,8 +576,8 @@
|
||||
// Check for controller specific errors.
|
||||
BOOL shouldContinue;
|
||||
MVMCoreErrorObject *error = [MVMCoreErrorObject createErrorObjectForErrorInfo:loadObject.responseInfoMap location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]];
|
||||
if ([loadObject.delegate respondsToSelector:@selector(checkForDelegateSpecificErrors:loadObject:completionHandler:)]) {
|
||||
shouldContinue = [loadObject.delegate checkForDelegateSpecificErrors:error loadObject:loadObject completionHandler:completionHandler];
|
||||
if ([loadObject.delegateObject.loadDelegate respondsToSelector:@selector(checkForDelegateSpecificErrors:loadObject:completionHandler:)]) {
|
||||
shouldContinue = [loadObject.delegateObject.loadDelegate checkForDelegateSpecificErrors:error loadObject:loadObject completionHandler:completionHandler];
|
||||
} else {
|
||||
shouldContinue = [MVMCoreLoadHandler defaultCheckForSpecificErrors:error loadObject:loadObject];
|
||||
}
|
||||
@ -621,8 +622,8 @@
|
||||
if (errorObject) {
|
||||
|
||||
// Check with the delegate if we should continue in the case of the module error.
|
||||
if ([loadObject.delegate respondsToSelector:@selector(handleModuleError:loadObject:error:)]) {
|
||||
shouldContinue = [loadObject.delegate handleModuleError:key loadObject:loadObject error:errorObject];
|
||||
if ([loadObject.delegateObject.loadDelegate respondsToSelector:@selector(handleModuleError:loadObject:error:)]) {
|
||||
shouldContinue = [loadObject.delegateObject.loadDelegate handleModuleError:key loadObject:loadObject error:errorObject];
|
||||
} else {
|
||||
shouldContinue = [MVMCoreLoadHandler defaultHandleModuleError:KeyCode loadObject:loadObject error:errorObject];
|
||||
}
|
||||
@ -784,24 +785,24 @@
|
||||
if (showAlertForErrorIfApplicable && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest) && !loadObject.requestParameters.handleErrorsSilently && !error.silentError && !error.errorScreenError) {
|
||||
|
||||
// Show alert for error.
|
||||
[MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:error actionDelegate:loadObject.operation.delegate];
|
||||
[MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:error delegateObject:loadObject.operation.delegateObject];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)createAndShowAlertForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nonnull id)actionDelegate {
|
||||
+ (void)createAndShowAlertForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Check delegate for alert object to show.
|
||||
MVMCoreAlertObject *alertObject;
|
||||
if ([actionDelegate respondsToSelector:@selector(alertObjectToShow:error:)]) {
|
||||
alertObject = [actionDelegate alertObjectToShow:loadObject error:error];
|
||||
if ([delegateObject.loadDelegate respondsToSelector:@selector(alertObjectToShow:error:)]) {
|
||||
alertObject = [delegateObject.loadDelegate alertObjectToShow:loadObject error:error];
|
||||
} else {
|
||||
alertObject = [MVMCoreAlertObject alertObjectForLoadObject:loadObject error:error actionDelegate:actionDelegate];
|
||||
alertObject = [MVMCoreAlertObject alertObjectForLoadObject:loadObject error:error delegateObject:delegateObject];
|
||||
}
|
||||
|
||||
// Set how we handle text field errors.
|
||||
[alertObject setTextFieldErrorHandler:^(NSArray * _Nonnull fieldErrors) {
|
||||
if ([loadObject.delegate respondsToSelector:@selector(handleFieldErrors:loadObject:)]) {
|
||||
[actionDelegate handleFieldErrors:fieldErrors loadObject:loadObject];
|
||||
if ([loadObject.operation.delegateObject.loadDelegate respondsToSelector:@selector(handleFieldErrors:loadObject:)]) {
|
||||
[loadObject.operation.delegateObject.loadDelegate handleFieldErrors:fieldErrors loadObject:loadObject];
|
||||
}
|
||||
}];
|
||||
|
||||
@ -815,7 +816,7 @@
|
||||
}
|
||||
|
||||
// Native driven error screens still need to be loaded. (as long as the delegate desires)
|
||||
if (!loadObject.requestParameters.handleErrorsSilently && !error.silentError && error.errorScreenError && (![loadObject.delegate respondsToSelector:@selector(shouldContinueToErrorPage:error:)] || [loadObject.delegate shouldContinueToErrorPage:loadObject error:error])) {
|
||||
if (!loadObject.requestParameters.handleErrorsSilently && !error.silentError && error.errorScreenError && (![loadObject.delegateObject.loadDelegate respondsToSelector:@selector(shouldContinueToErrorPage:error:)] || [loadObject.delegateObject.loadDelegate shouldContinueToErrorPage:loadObject error:error])) {
|
||||
[MVMCoreLoadRequestOperation handleError:error loadObject:loadObject showAlertForErrorIfApplicable:YES];
|
||||
[MVMCoreLoadRequestOperation handleLoadObject:loadObject error:error];
|
||||
} else {
|
||||
@ -833,13 +834,14 @@
|
||||
// Show any alerts that we have been saving.
|
||||
if (loadObject.operation.alertToShow) {
|
||||
|
||||
id actionDelegate = loadedViewController ?: loadObject.operation.delegate;
|
||||
[MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:loadObject.operation.errorForAlertToShow actionDelegate:actionDelegate];
|
||||
// If we have an alert to show and a loaded view controller, allow the loaded view controller to be the delegate.
|
||||
DelegateObject *delegateObject = [loadedViewController respondsToSelector:@selector(delegateObject)] ? [loadedViewController delegateObject] : loadObject.operation.delegateObject;
|
||||
[MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:loadObject.operation.errorForAlertToShow delegateObject:delegateObject];
|
||||
}
|
||||
|
||||
// Notify delegate that the load has finished
|
||||
if ([loadObject.delegate respondsToSelector:@selector(loadFinished:loadedViewController:error:)]) {
|
||||
[loadObject.delegate loadFinished:loadObject loadedViewController:loadedViewController error:errorObject];
|
||||
if ([loadObject.delegateObject.loadDelegate respondsToSelector:@selector(loadFinished:loadedViewController:error:)]) {
|
||||
[loadObject.delegateObject.loadDelegate loadFinished:loadObject loadedViewController:loadedViewController error:errorObject];
|
||||
} else {
|
||||
[MVMCoreLoggingHandler logWithDelegateLoadFinished:loadObject loadedViewController:loadedViewController error:errorObject];
|
||||
}
|
||||
@ -855,30 +857,30 @@
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:NO];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) {
|
||||
[self.delegate navigationController:navigationController willDisplayViewController:viewController];
|
||||
if ([self.delegateObject.presentationDelegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) {
|
||||
[self.delegateObject.presentationDelegate navigationController:navigationController willDisplayViewController:viewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)navigationController:(UINavigationController *)navigationController displayedViewController:(UIViewController *)viewController {
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) {
|
||||
[self.delegate navigationController:navigationController displayedViewController:viewController];
|
||||
if ([self.delegateObject.presentationDelegate respondsToSelector:@selector(navigationController:displayedViewController:)]) {
|
||||
[self.delegateObject.presentationDelegate navigationController:navigationController displayedViewController:viewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:animationControllerForOperation:fromViewController:toViewController:)]) {
|
||||
if (self.delegateObject.presentationDelegate && [self.delegateObject.presentationDelegate respondsToSelector:@selector(navigationController:animationControllerForOperation:fromViewController:toViewController:)]) {
|
||||
|
||||
return [self.delegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
|
||||
return [self.delegateObject.presentationDelegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) {
|
||||
return [self.delegate navigationController:navigationController interactionControllerForAnimationController:animationController];
|
||||
if (self.delegateObject.presentationDelegate && [self.delegateObject.presentationDelegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) {
|
||||
return [self.delegateObject.presentationDelegate navigationController:navigationController interactionControllerForAnimationController:animationController];
|
||||
} else {
|
||||
return nil;
|
||||
}
|
||||
@ -886,15 +888,37 @@
|
||||
|
||||
- (void)viewController:(UIViewController *)presentingViewController willPresentViewController:(UIViewController *)presentedViewController {
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) {
|
||||
[self.delegate viewController:presentingViewController willPresentViewController:presentedViewController];
|
||||
if ([self.delegateObject.presentationDelegate respondsToSelector:@selector(viewController:willPresentViewController:)]) {
|
||||
[self.delegateObject.presentationDelegate viewController:presentingViewController willPresentViewController:presentedViewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewController:(UIViewController *)presentingViewController didPresentViewController:(UIViewController *)presentedViewController {
|
||||
if ([self.delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) {
|
||||
[self.delegate viewController:presentingViewController didPresentViewController:presentedViewController];
|
||||
if ([self.delegateObject.presentationDelegate respondsToSelector:@selector(viewController:didPresentViewController:)]) {
|
||||
[self.delegateObject.presentationDelegate viewController:presentingViewController didPresentViewController:presentedViewController];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Deprecated
|
||||
|
||||
- (void)setDelegateObject:(DelegateObject *)delegateObject {
|
||||
_delegateObject = delegateObject;
|
||||
_delegate = delegateObject.loadDelegate;
|
||||
}
|
||||
|
||||
- (void)setDelegate:(NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol> *)delegate {
|
||||
_delegate = delegate;
|
||||
_delegateObject = [DelegateObject createWithDelegateForAll:delegate];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegate:(nullable NSObject<MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate backgroundLoad:(BOOL)backgroundLoad {
|
||||
if (self = [super init]) {
|
||||
self.requestParameters = requestParameters;
|
||||
self.dataForPage = dataForPage;
|
||||
self.delegate = delegate;
|
||||
self.backgroundLoad = backgroundLoad;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
36
MVMCore/MVMCore/MainProtocols/DelegateObject.swift
Normal file
36
MVMCore/MVMCore/MainProtocols/DelegateObject.swift
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// DelegateObject.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Scott Pfeil on 4/12/19.
|
||||
// Copyright © 2019 myverizon. All rights reserved.
|
||||
//
|
||||
// An object that references delegates for the many protocols our framework uses.
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class DelegateObject: NSObject {
|
||||
public weak var actionDelegate: (MVMCoreActionDelegateProtocol & NSObjectProtocol)?
|
||||
public weak var loadDelegate: (MVMCoreLoadDelegateProtocol & NSObjectProtocol)?
|
||||
public weak var alertDelegate: (MVMCoreAlertDelegateProtocol & NSObjectProtocol)?
|
||||
public weak var topAlertDelegate: (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol)?
|
||||
public weak var presentationDelegate: (MVMCorePresentationDelegateProtocol & NSObjectProtocol)?
|
||||
|
||||
required override public init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
open func setAll(withDelegate delegate: Any) {
|
||||
actionDelegate = delegate as? (MVMCoreActionDelegateProtocol & NSObjectProtocol)
|
||||
loadDelegate = delegate as? (MVMCoreLoadDelegateProtocol & NSObjectProtocol)
|
||||
alertDelegate = delegate as? (MVMCoreAlertDelegateProtocol & NSObjectProtocol)
|
||||
topAlertDelegate = delegate as? (MVMCoreTopAlertDelegateProtocol & NSObjectProtocol)
|
||||
presentationDelegate = delegate as? (MVMCorePresentationDelegateProtocol & NSObjectProtocol)
|
||||
}
|
||||
|
||||
static public func create(withDelegateForAll delegate: Any) -> Self {
|
||||
let delegateObject = self.init()
|
||||
delegateObject.setAll(withDelegate: delegate)
|
||||
return delegateObject
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
@class MVMCoreLoadObject;
|
||||
@class MVMCoreErrorObject;
|
||||
@class DelegateObject;
|
||||
|
||||
@protocol MVMCoreViewControllerProtocol <NSObject>
|
||||
|
||||
@ -17,5 +18,10 @@
|
||||
// This view controller should subclass this function and check the load to make sure it has all the needed data. Fills the error object if there are any errors. Returns if we should finish the load or not. Ideally error should use code ErrorCodeViewControllerProcessingJSON.
|
||||
- (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error;
|
||||
|
||||
@optional
|
||||
|
||||
// Allows override of the delegate to use.
|
||||
- (nullable DelegateObject *)delegateObject;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user