blob: a47f0673395502158c3299257ed5fcf7ed7fee84 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Flutter
import Foundation
public final class IosPlatformImagesPlugin: NSObject, FlutterPlugin, PlatformImagesApi {
public static func register(with registrar: FlutterPluginRegistrar) {
let instance = IosPlatformImagesPlugin()
let messenger = registrar.messenger()
PlatformImagesApiSetup.setUp(binaryMessenger: messenger, api: instance)
}
func loadImage(name: String) -> PlatformImageData? {
guard let image = UIImage(named: name),
let data = image.pngData()
else {
return nil
}
return PlatformImageData(
data: FlutterStandardTypedData(bytes: data), scale: Double(image.scale))
}
func resolveUrl(resourceName: String, extension: String?) throws -> String? {
guard
let url = Bundle.main.url(
forResource: resourceName,
withExtension: `extension`)
else {
return nil
}
return url.absoluteString
}
}