diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index fc302b5..a524c2a 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -38,8 +38,6 @@ 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */; }; 8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */; }; - 88D1FBE11FCCCBA100338A3A /* MVMCoreMainSplitViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 88D1FBE21FCCCBA500338A3A /* PanelProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; }; @@ -165,8 +163,6 @@ 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+MFSpacing.m"; sourceTree = ""; }; 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+MFCustom.h"; sourceTree = ""; }; 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+MFCustom.m"; sourceTree = ""; }; - 88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreMainSplitViewProtocol.h; sourceTree = ""; }; - 88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PanelProtocol.h; sourceTree = ""; }; A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = ""; }; AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = ""; }; AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; @@ -318,7 +314,6 @@ AFBB96DE1FBA48CE0008D868 /* Singletons */, AF43A70C1FC4F42B008E9347 /* Session */, AFBB96D41FBA48240008D868 /* OtherHandlers */, - AF43A5941FBB700D008E9347 /* MainStructure */, AF26DDAB1FCE5CF2004E8F65 /* Strings */, 8876D5CC1FB50A9E00EB2E3D /* MVMCore.h */, 8876D5CD1FB50A9E00EB2E3D /* Info.plist */, @@ -366,15 +361,6 @@ path = Strings; sourceTree = ""; }; - AF43A5941FBB700D008E9347 /* MainStructure */ = { - isa = PBXGroup; - children = ( - 88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */, - 88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */, - ); - path = MainStructure; - sourceTree = ""; - }; AF43A6FC1FBE2F2A008E9347 /* Reachability */ = { isa = PBXGroup; children = ( @@ -622,7 +608,6 @@ AF43A7201FC5D2BA008E9347 /* MVMCoreViewManagerProtocol.h in Headers */, 881D26951FCC9D180079C521 /* MVMCoreErrorObject.h in Headers */, AFBB96341FBA34310008D868 /* MVMCoreErrorConstants.h in Headers */, - 88D1FBE21FCCCBA500338A3A /* PanelProtocol.h in Headers */, A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */, AFBB968D1FBA3A9A0008D868 /* MVMCoreNavigationHandler.h in Headers */, AFBB96A51FBA3A9A0008D868 /* MVMCoreTopAlertOperation.h in Headers */, @@ -647,7 +632,6 @@ AFEEE81E1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h in Headers */, AF43A7011FC4B227008E9347 /* MVMCoreGlobalLoadProtocol.h in Headers */, AF43A5771FBA5B7C008E9347 /* MVMCoreJSONConstants.h in Headers */, - 88D1FBE11FCCCBA100338A3A /* MVMCoreMainSplitViewProtocol.h in Headers */, AFBB96631FBA3A570008D868 /* MVMCoreLoadRequestOperation.h in Headers */, AFC5FA1D1FFC39C700C244CF /* MVMCoreTopAlertViewProtocol.h in Headers */, AFBB969D1FBA3A9A0008D868 /* MVMCoreAlertObject.h in Headers */, @@ -962,11 +946,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/MVMCore/EmbeddedLibaries/AdobeMobileLibrary", - "$(PROJECT_DIR)/MVMCore/EmbeddedLibraries/VZAnalytics", - ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -991,11 +971,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/MVMCore/EmbeddedLibaries/AdobeMobileLibrary", - "$(PROJECT_DIR)/MVMCore/EmbeddedLibraries/VZAnalytics", - ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 94211c8..4e95c40 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -36,6 +36,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; @implementation MVMCoreActionHandler + (nullable instancetype)sharedActionHandler { + [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].actionHandler.class otherClass:self throwException:YES]; return [MVMCoreObject sharedInstance].actionHandler; } diff --git a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertDelegateProtocol.h b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertDelegateProtocol.h index 4e3158f..af09483 100644 --- a/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertDelegateProtocol.h +++ b/MVMCore/MVMCore/AlertHandling/MVMCoreTopAlertDelegateProtocol.h @@ -17,4 +17,7 @@ - (void)topAlertViewShown:(nonnull id)topAlert topAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject; - (void)topAlertViewDismissed:(nonnull id)topAlert; +// Called when the top alert is pressed. Determines if we should load the option the default way or not. +- (BOOL)shouldLoadTopAlertAction:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; + @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 7f00738..3938e8b 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -721,13 +721,13 @@ completionHandler(viewController,loadObject); } else { - // Initialize the view controller using the pageType-ViewController mapping. (on the main thread) + // Initialize the view controller using the ViewController mapping. (on the main thread) [MVMCoreDispatchUtility performBlockOnMainThread:^{ - __block MVMCoreErrorObject *error = nil; - __block UIViewController *viewController = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] createMFViewControllerOfPageType:loadObject.pageType error:&error]; + __block UIViewController *viewController = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] createMFViewControllerOfTemplate:[loadObject.pageJSON string:@"template"] pageType:loadObject.pageType]; [MVMCoreDispatchUtility performBlockInBackground:^{ + MVMCoreErrorObject *error = nil; BOOL shouldContinue = NO; if (viewController) { @@ -743,10 +743,6 @@ viewController = nil; } } - } else if (error) { - - // Sets the location for the error. - error.location = [[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]; } else { // Couldn't initialize view controller, serious error. error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeInitViewController domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index 2fd8fae..f5db9c6 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -43,10 +43,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; #import #import -// Main Structure -#import -#import - // Load Handling #import #import diff --git a/MVMCore/MVMCore/MainProtocols/MVMCoreViewControllerProtocol.h b/MVMCore/MVMCore/MainProtocols/MVMCoreViewControllerProtocol.h index 641c630..d951d03 100644 --- a/MVMCore/MVMCore/MainProtocols/MVMCoreViewControllerProtocol.h +++ b/MVMCore/MVMCore/MainProtocols/MVMCoreViewControllerProtocol.h @@ -12,24 +12,10 @@ @protocol MVMCoreViewControllerProtocol -// TODO: need to be moved out when core is completely finished -@property (nonatomic) BOOL masterShouldBeAccessible; -@property (nonatomic) BOOL supportShouldBeAccessible; -@property (nonatomic) BOOL cartShouldBeAccessible; -@property (nonatomic) BOOL communityShouldBeAccessible; -@property (nonatomic) BOOL closeButtonAccessible; -@property (nullable, nonatomic, readonly) NSDictionary *closeButtonActionMap; - - @property (nullable, strong, nonatomic) NSString *pageType; // 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 - -// Called when the back button is pressed. Overwrite for special functionality. Default is to just popviewcontroller. -- (void)backButtonPressed; - @end diff --git a/MVMCore/MVMCore/MainStructure/MVMCoreMainSplitViewProtocol.h b/MVMCore/MVMCore/MainStructure/MVMCoreMainSplitViewProtocol.h deleted file mode 100644 index 7de9c9e..0000000 --- a/MVMCore/MVMCore/MainStructure/MVMCoreMainSplitViewProtocol.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// MainSplitViewProtocol.h -// MVMCore -// -// Created by Pfeil, Scott Robert on 11/14/17. -// Copyright © 2017 myverizon. All rights reserved. -// - -#import -#import - -@protocol MVMCoreMainSplitViewProtocol - -// Provide the panels that you would like to use. -- (nullable UIViewController *)getLeftPanel; -- (nullable UIViewController *)getRightPanel; - -@end diff --git a/MVMCore/MVMCore/MainStructure/PanelProtocol.h b/MVMCore/MVMCore/MainStructure/PanelProtocol.h deleted file mode 100644 index 2db89c7..0000000 --- a/MVMCore/MVMCore/MainStructure/PanelProtocol.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// PanelProtocol.h -// mobilefirst -// -// Created by Seshamani, Shreyas on 6/2/17. -// Copyright © 2017 Verizon Wireless. All rights reserved. -// - -#import -#import -@protocol PanelProtocol - -#pragma mark - life cycle - -@optional - -// The panel can return if it should be available or not. -- (BOOL)panelAvailable; - -- (void)panel:(UIViewController *_Nullable)panel viewWillAppear:(BOOL)animated; -- (void)panel:(UIViewController *_Nullable)panel viewDidAppear:(BOOL)animated; -- (void)panel:(UIViewController *_Nullable)panel viewWillDisappear:(BOOL)animated; -- (void)panel:(UIViewController *_Nullable)panel viewDidDisappear:(BOOL)animated; - -- (void)showArrow; -- (void)hideArrow; - -- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation; - -- (void)clearData; -- (void)resetIconToDefault; - -- (void)getCurrentDetailViewController:(nullable UIViewController *)currentViewController;//in menu - -@end diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index bb97f89..116c352 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -14,6 +14,7 @@ #import "MVMCoreGetterUtility.h" #import "MVMCoreObject.h" #import "MVMCoreConstants.h" +#import "MVMCoreActionUtility.h" @interface MVMCoreCache () @@ -41,6 +42,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; + (nullable instancetype)sharedCache { + [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].cache.class otherClass:self throwException:YES]; return [MVMCoreObject sharedInstance].cache; } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h index 12d0e2a..557ac8e 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.h @@ -17,6 +17,8 @@ @interface MVMCoreLoggingHandler : NSObject ++ (nullable instancetype)sharedLoggingHandler; + + (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject; + (void)logDebugMessageWithDelegate:(nullable NSString *)message; + (void)logWithDelegateWithObject:(nullable id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m index 65e2659..82ad77a 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.m @@ -8,9 +8,18 @@ #import "MVMCoreLoggingHandler.h" #import "MVMCoreObject.h" +#import "MVMCoreActionUtility.h" @implementation MVMCoreLoggingHandler ++ (nullable instancetype)sharedLoggingHandler { + if ([MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].loggingDelegate.class otherClass:self throwException:NO]) { + return (MVMCoreLoggingHandler *)[MVMCoreObject sharedInstance].loggingDelegate; + } else { + return nil; + } +} + + (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject { if (errorObject && [[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(addErrorToLog:)]) { [[MVMCoreObject sharedInstance].loggingDelegate addErrorToLog:errorObject]; diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index b49132d..5deb1e4 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -8,10 +8,12 @@ #import "MVMCoreSessionObject.h" #import "MVMCoreObject.h" +#import "MVMCoreActionUtility.h" @implementation MVMCoreSessionObject + (nullable instancetype)sharedGlobal { + [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].session.class otherClass:self throwException:YES]; return [MVMCoreObject sharedInstance].session; } diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m index f0f632d..a18113f 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionTimeHandler.m @@ -18,6 +18,7 @@ #import "MVMCoreRequestParameters.h" #import "NSDictionary+MFConvenience.h" #import "MVMCoreObject.h" +#import "MVMCoreActionUtility.h" @interface MVMCoreSessionTimeHandler () @@ -46,6 +47,7 @@ @implementation MVMCoreSessionTimeHandler + (nullable instancetype)sharedSessionHandler { + [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].sessionHandler.class otherClass:self throwException:YES]; return [MVMCoreObject sharedInstance].sessionHandler; } diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.h b/MVMCore/MVMCore/Singletons/MVMCoreObject.h index 438cad2..ebdf435 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.h +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.h @@ -14,9 +14,9 @@ #import #import #import -#import #import #import +#import @interface MVMCoreObject : NSObject @@ -27,10 +27,9 @@ @property (nullable, strong, nonatomic) MVMCoreSessionTimeHandler *sessionHandler; // The delegates -@property (nullable, weak, nonatomic) NSObject *splitViewDelegate; @property (nullable, weak, nonatomic) id globalLoadDelegate; @property (nullable, weak, nonatomic) id loadingProtocol; -@property (nullable, weak, nonatomic) id loggingDelegate; +@property (nullable, weak, nonatomic) NSObject *loggingDelegate; @property (nullable, weak, nonatomic) id globalTopAlertDelegate; // A reference to the calling application delegate that should be set. For a normal app, could be the UIApplicationDelegate. For watch, could be WKExtensionDelegate. For iMessage, could be MSMessagesAppViewController. etc, etc. Useful for the framework to call delegate specific functions. diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.h b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.h index a5b4de0..76f1d8e 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.h +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.h @@ -23,4 +23,7 @@ // Can call to display a view controller based on the load object in the same way the architecture does it. Will check the presentation style of the page, action, and request. Will check if needs a view manager. + (void)displayViewController:(nonnull UIViewController *)viewController forLoadObject:(nullable MVMCoreLoadObject *)loadObject presentationDelegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock; +// returns if the class is not the same or a subclass of the other class. Can pass throw an exception as well ++ (BOOL)classIsInstanceTypeOfClass:(Class)theClass otherClass:(Class)otherClass throwException:(BOOL)throwException; + @end diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.m b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.m index 2505762..f350b6c 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.m +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreActionUtility.m @@ -137,4 +137,14 @@ [[MVMCoreNavigationHandler sharedNavigationHandler] navigateWithLoadObject:loadObject viewController:(viewControllerToLoad ?: viewController) delegate:delegate completionHandler:completionBlock]; } ++ (BOOL)classIsInstanceTypeOfClass:(Class)theClass otherClass:(Class)otherClass throwException:(BOOL)throwException { + if (theClass != otherClass && ![theClass isSubclassOfClass:otherClass]) { + if (throwException) { + @throw([NSException exceptionWithName:@"NotInstanceType" reason:[NSString stringWithFormat:@"%@ is not an instance of %@",theClass,otherClass] userInfo:nil]); + } + return NO; + } + return YES; +} + @end diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h index ef653c4..262cc75 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.h @@ -25,4 +25,7 @@ // Returns a UIColor + (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString; +// Returns if the device is an ipad ++ (BOOL)isOnIPad; + @end diff --git a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m index b2a3e11..b48f34e 100644 --- a/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m +++ b/MVMCore/MVMCore/Utility/Helpers/MVMCoreGetterUtility.m @@ -50,4 +50,12 @@ alpha:1]; } ++ (BOOL)isOnIPad { + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + return YES; + } else { + return NO; + } +} + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h index 0ba210c..27b6078 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h @@ -5,31 +5,50 @@ // Created by Scott Pfeil on 12/2/13. // Copyright (c) 2013 Verizon Wireless. All rights reserved. // -// Any given pageType will map to a view controller. This object tells if it is loaded from a story board with the id in viewControllerString. If wish to load from nib, leave storyBoard nil, and viewControllerString the nib name. +// Singleton for using template id string to create view controllers based on mapping objects. Any given templateID will map to a view controller. #import #import @class MVMCoreErrorObject; +// Classes that use the protocol should be able to be added to the mapping and create a view controller when called upon. +@protocol MVMCoreViewControllerMappingProtocol + +// Creates and returns an mvm view controller. +- (nullable UIViewController *)createViewController; + +@end + @interface MVMCoreViewControllerMappingObject : NSObject -@property (nullable, strong, nonatomic) NSMutableDictionary *viewControllerMapping; +// The template based mapping. +@property (nullable, strong, nonatomic) NSMutableDictionary *> *viewControllerMapping; + +// The modules that the page can't survive without. Will throw an error if not all are found during loading. @property (nullable, strong, nonatomic) NSMutableDictionary *requiredModuleMapping; + +// The modules that the page will ask for but may not get. @property (nullable, strong, nonatomic) NSMutableDictionary *optionalModuleMapping; +// Legacy: page type based mapping +@property (nullable, strong, nonatomic) NSMutableDictionary *> *pageTypeViewControllerMapping; + // Returns the shared instance + (nullable instancetype)sharedViewControllerMappingObject; #pragma mark - View Controller Mapping -// Returns the mapping object which maps the given page type to how it's view controller is loaded. -- (nullable MVMCoreViewControllerMappingObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType; +// Returns the mapping object which maps the given template to how it's view controller is loaded. +- (nullable NSObject *)getViewControllerMappingForTemplate:(nonnull NSString *)templateID; + +// Creates and returns an mvm view controller of the passed in template or page type using the mapping. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID; // For pages external to the mobile first framework to be added to the view controller mapping. -- (void)addToViewControllerMapping:(nullable NSDictionary *)map; +- (void)addToTemplateViewControllerMapping:(nullable NSDictionary *>*)map; -// Creates and returns an mvm view controller of the passed in page type using the mapping. -- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error; +// Transition function: A mix of new and legacy. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nullable NSString *)templateID pageType:(nullable NSString *)pageType; #pragma mark - Module PageType Mapping @@ -51,4 +70,15 @@ // Add optional modules for multiple pages. Used by external frameworks - (void)addOptionalModulesForPages:(nonnull NSDictionary*>*)optionalModulesForPages; +#pragma mark - Legacy PageType driven + +// Returns the mapping object which maps the given page type to how it's view controller is loaded. +- (nullable NSObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType; + +// For pages external to the mobile first framework to be added to the view controller mapping for pagetypes. +- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary *>*)map; + +// Creates and returns an mvm view controller of the passed in template or page type using the mapping. +- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType; + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m index 1bc9fe0..d39193e 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m @@ -18,6 +18,7 @@ #import "MVMCoreErrorConstants.h" #import "MVMCoreHardcodedStringsConstants.h" #import "MVMCoreObject.h" +#import "MVMCoreActionUtility.h" @interface MVMCoreViewControllerMappingObject () @@ -26,62 +27,35 @@ @implementation MVMCoreViewControllerMappingObject + (nullable instancetype)sharedViewControllerMappingObject { + [MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].viewControllerMapping.class otherClass:self throwException:YES]; return [MVMCoreObject sharedInstance].viewControllerMapping; } #pragma mark - View Controller Mapping -- (nullable MVMCoreViewControllerMappingObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType { - return [self.viewControllerMapping objectForKey:pageType]; +- (nullable NSObject *)getViewControllerMappingForTemplate:(nonnull NSString *)templateID { + return [self.viewControllerMapping objectForKey:templateID]; } -- (void)addToViewControllerMapping:(nullable NSDictionary *)map { +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID { + return [[self getViewControllerMappingForTemplate:templateID] createViewController]; +} + +- (void)addToTemplateViewControllerMapping:(nullable NSDictionary *>*)map { if (map) { [self.viewControllerMapping addEntriesFromDictionary:map]; } } -- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error { - - // Initialize the view controller using the pageType-ViewController mapping. - UIViewController *viewController = nil; - - MVMCoreViewControllerMappingObject *mapping = [self getViewControllerMappingForPageType:pageType]; - if ([mapping isKindOfClass:[MVMCoreViewControllerStoryBoardMappingObject class]]) { - - // Initialize from story board. - NSString *storyboardName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).storyBoard; - NSString *viewIdentifier = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).storyBoardIdentifier; - NSString *bundleName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).bundleName; - if (storyboardName.length != 0 && viewIdentifier.length != 0 && bundleName) { - UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:[NSBundle bundleWithIdentifier:bundleName]]; - viewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:viewIdentifier]; - } else if (error) { - - NSInteger code = 0; - if (storyboardName.length == 0) { - code = ErrorCodeNoStoryboardName; - } else if (viewIdentifier.length == 0) { - code = ErrorCodeNoStoryBoardIdentifier; - } - *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:code domain:ErrorDomainNative location:nil]; - } - } else if ([mapping isKindOfClass:[MVMCoreViewControllerNibMappingObject class]]) { - - // Initialize from nib - NSString *viewControllerNibName = ((MVMCoreViewControllerNibMappingObject *)mapping).nibName; - NSString *bundleName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).bundleName; - if (viewControllerNibName.length != 0) { - viewController = [[((MVMCoreViewControllerNibMappingObject *)mapping).viewControllerClass alloc] initWithNibName:viewControllerNibName bundle:[NSBundle bundleWithIdentifier:bundleName]]; - } else if (error) { - *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeNoNibName domain:ErrorDomainNative location:nil]; - } +// Transition function: A mix of new and legacy. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nullable NSString *)templateID pageType:(nullable NSString *)pageType { + if (templateID) { + return [self createMFViewControllerOfTemplate:templateID]; + } else if (pageType) { + return [self createMFViewControllerOfPageType:pageType]; } else { - // Initialize programmatically. - viewController = [[((MVMCoreViewControllerProgrammaticMappingObject *)mapping).viewControllerClass alloc] init]; + return nil; } - - return viewController; } #pragma mark - Module PageType Mapping @@ -128,5 +102,21 @@ [self.optionalModuleMapping addEntriesFromDictionary:optionalModulesForPages]; } } + +#pragma mark - Legacy PageType driven + +- (nullable NSObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType { + return [self.pageTypeViewControllerMapping objectForKey:pageType]; +} + +- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary *>*)map { + if (map) { + [self.pageTypeViewControllerMapping addEntriesFromDictionary:map]; + } +} + +- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType { + return [[self getViewControllerMappingForPageType:pageType] createViewController]; +} @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h index a862c1d..fa7c2d7 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerNibMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerNibMappingObject : NSObject // View Controller Class, for loading from a nib. @property (nonnull, strong, nonatomic) Class viewControllerClass; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m index 9d82eab..cb8d93c 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m @@ -21,4 +21,9 @@ return self; } +- (nullable UIViewController *)createViewController { + // Initialize from nib + return [[self.viewControllerClass alloc] initWithNibName:self.nibName bundle:[NSBundle bundleWithIdentifier:self.bundleName]]; +} + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h index be973b5..02487e0 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerProgrammaticMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerProgrammaticMappingObject : NSObject // View Controller Class, for loading by class. @property (nonnull, strong, nonatomic) Class viewControllerClass; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m index b00a785..8547285 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m @@ -19,4 +19,8 @@ return self; } +- (nullable UIViewController *)createViewController { + return [[self.viewControllerClass alloc] init]; +} + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h index 8847427..51fb398 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerStoryBoardMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerStoryBoardMappingObject : NSObject // Initializes with a story board load. - (nullable id)initWithStoryBoard:(nonnull NSString *)storyBoard storyBoardIdentifier:(nonnull NSString *)storyBoardIdentifier bundleName:(nonnull NSString *)bundleName; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m index 69744ab..55f0eb1 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m @@ -21,4 +21,10 @@ return self; } +- (nullable UIViewController *)createViewController { + // Initialize from story board. + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:self.storyBoard bundle:[NSBundle bundleWithIdentifier:self.bundleName]]; + return [storyboard instantiateViewControllerWithIdentifier:self.storyBoardIdentifier]; +} + @end