Move legacy delegate call out of core.
This commit is contained in:
parent
a2d9196bca
commit
c21b677048
@ -13,43 +13,33 @@ open class ActionOpenUrlHandler: MVMCoreActionHandlerProtocol {
|
|||||||
|
|
||||||
open func handleAction(_ model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
open func handleAction(_ model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||||
guard let model = model as? ActionOpenUrlModel else { return }
|
guard let model = model as? ActionOpenUrlModel else { return }
|
||||||
let linkAway = { [self] (appURL: URL?, browserURL: URL?, actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) in
|
MVMCoreDispatchUtility.performBlock(onMainThread: { [self] in
|
||||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
// Try loading the app url first, otherwise fall back to browser url.
|
||||||
// Try loading the app url first, otherwise fall back to browser url.
|
guard let appURL = model.appURL else {
|
||||||
guard let appURL = appURL else {
|
openURL(model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
open(url: browserURL, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
return
|
||||||
return
|
}
|
||||||
}
|
UIApplication.shared.open(appURL, options: model.appURLOptions?.options ?? [:]) { loaded in
|
||||||
UIApplication.shared.open(appURL, options: model.appURLOptions?.options ?? [:]) { loaded in
|
guard !loaded else { return }
|
||||||
guard !loaded else { return }
|
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Failed to open app url: \(appURL)")
|
||||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Failed to open app url: \(appURL)")
|
openURL(model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
open(url: browserURL, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow legacy Delegate intercept for now.
|
|
||||||
let actionInformation = model.toJSON()
|
|
||||||
delegateObject?.actionDelegate?.shouldLinkAway?(with: model.browserUrl, appURL: model.appURL, actionInformation: actionInformation, additionalData: additionalData, linkAwayBlock: linkAway) ?? linkAway(model.appURL, model.browserUrl, actionInformation, additionalData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens the url.
|
/// Opens the url.
|
||||||
open func open(url: URL?, model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
open func openURL(model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||||
guard let url = url else {
|
UIApplication.shared.open(model.browserUrl, options: [:]) { [self] loaded in
|
||||||
handleError(url: url, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
UIApplication.shared.open(url, options: [:]) { [self] loaded in
|
|
||||||
guard !loaded else { return }
|
guard !loaded else { return }
|
||||||
handleError(url: url, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
handleError(model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles any url loading errors.
|
/// Handles any url loading errors.
|
||||||
open func handleError(url: URL?, model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
open func handleError(model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||||
if let error = MVMCoreErrorObject(title: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorTitle),
|
if let error = MVMCoreErrorObject(title: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorTitle),
|
||||||
message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess),
|
message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess),
|
||||||
messageToLog: "Unable to load URL: \(String(describing: url))", code: ErrorCode.linkawayFailed.rawValue,
|
messageToLog: "Unable to load URL: \(String(describing: model.browserUrl))", code: ErrorCode.linkawayFailed.rawValue,
|
||||||
domain: ErrorDomainNative,
|
domain: ErrorDomainNative,
|
||||||
location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: ActionOpenUrlModel.identifier)) {
|
location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: ActionOpenUrlModel.identifier)) {
|
||||||
MVMCoreDispatchUtility.performBlock(inBackground: {
|
MVMCoreDispatchUtility.performBlock(inBackground: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user