blob: b41ff9900d8e4aa3d0ce31cd327e94a1e7267748 [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 "IosPlatformImagesPlugin.h"
#if !__has_feature(objc_arc)
#error ARC must be enabled!
#endif
@interface IosPlatformImagesPlugin ()
@end
@implementation IosPlatformImagesPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FPIPlatformImagesApiSetup(registrar.messenger, [[IosPlatformImagesPlugin alloc] init]);
}
- (nullable FPIPlatformImageData *)
loadImageWithName:(nonnull NSString *)name
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
UIImage *image = [UIImage imageNamed:name];
NSData *data = UIImagePNGRepresentation(image);
if (!data) {
return nil;
}
return [FPIPlatformImageData makeWithData:[FlutterStandardTypedData typedDataWithBytes:data]
scale:@(image.scale)];
}
- (nullable NSString *)resolveURLForResource:(nonnull NSString *)name
withExtension:(nullable NSString *)extension
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)
error {
NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:extension];
return url.absoluteString;
}
@end