You can register the way remote images will be downloaded and populated in UIImageView by providing a class that implements this logic, which was added to Beagle in version 1.3.0.
With ImageDownloader being created in the frontend of your iOS application, Beagle will know which logic to use to download and configure the Image component of type ImagePath.Remote.
The ImageDownloader protocol consists of only one method called fetchImage that will be used to request your remote images.
public protocol ImageDownloader {
@discardableResult
func fetchImage(
url: String,
additionalData: RemoteScreenAdditionalData?,
completion: @escaping (Result<Data, Request.Error>) -> Void
) -> RequestToken?
}
The fetchImage method takes 3 parameters:
In addition, the function can return a RequestToken so that the request can be canceled internally by Beagle.
In Beagle iOS, we have a class called ImageDownloaderDefault that performs the requests for images according to your network layer.
In its fetchImage
method, this class calls RequestDispatcher with type .fetchImage
and maps the result of that request according to the implementation of your network layer. You can see how to configure a network layer in here.
To replace the class responsible for making image requests on Beagle, follow the steps below:
ImageDownloader
Implement the ImageDownloader
protocol in the class you wish to use to make requests, in this case we created a class CustomImageDownloader
that will be used as an example:
class CustomImageDownloader: ImageDownloader {
func fetchImage(
url: String,
additionalData: RemoteScreenAdditionalData?,
completion: @escaping (Result<Data, Request.Error>) -> Void
) -> RequestToken? {
let newUrl: URL = URL(string: url)
//Implementation of image request
}
//Additional implementation...
}
In AppDelegate or in Beagle environment settings class, assign the instance of CustomImageDownloader
to the imageDownloader
attribute present in BeagleDependencies:
let dependencies = BeagleDependencies()
let customImageDownloader = CustomImageDownloader()
dependencies.imageDownloader = customImageDownloader
Beagle.dependencies = dependencies
Done! Beagle will now use your class with all the necessary modifications and settings to download your remote images.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.