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?) {
|
||||
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: {
|
||||
// Try loading the app url first, otherwise fall back to browser url.
|
||||
guard let appURL = appURL else {
|
||||
open(url: browserURL, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||
return
|
||||
}
|
||||
UIApplication.shared.open(appURL, options: model.appURLOptions?.options ?? [:]) { loaded in
|
||||
guard !loaded else { return }
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Failed to open app url: \(appURL)")
|
||||
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)
|
||||
MVMCoreDispatchUtility.performBlock(onMainThread: { [self] in
|
||||
// Try loading the app url first, otherwise fall back to browser url.
|
||||
guard let appURL = model.appURL else {
|
||||
openURL(model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||
return
|
||||
}
|
||||
UIApplication.shared.open(appURL, options: model.appURLOptions?.options ?? [:]) { loaded in
|
||||
guard !loaded else { return }
|
||||
MVMCoreLoggingHandler.shared()?.handleDebugMessage("Failed to open app url: \(appURL)")
|
||||
openURL(model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Opens the url.
|
||||
open func open(url: URL?, model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||
guard let url = url else {
|
||||
handleError(url: url, model: model, additionalData: additionalData, delegateObject: delegateObject)
|
||||
return
|
||||
}
|
||||
UIApplication.shared.open(url, options: [:]) { [self] loaded in
|
||||
open func openURL(model: ActionOpenUrlModel, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?) {
|
||||
UIApplication.shared.open(model.browserUrl, options: [:]) { [self] loaded in
|
||||
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.
|
||||
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),
|
||||
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,
|
||||
location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: ActionOpenUrlModel.identifier)) {
|
||||
MVMCoreDispatchUtility.performBlock(inBackground: {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user