URLImageView.m revision 2beebed98b4fc7f018fb224a1e4a3ab6103a4c0b
59190ecd61435d19ba3515b876272aee7bd12298vboxsync/*
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * The contents of this file are subject to the terms of the Common Development and
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * Distribution License (the License). You may not use this file except in compliance with the
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * License.
59190ecd61435d19ba3515b876272aee7bd12298vboxsync *
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * specific language governing permission and limitations under the License.
59190ecd61435d19ba3515b876272aee7bd12298vboxsync *
c55c68b6a3324172e9dc207926215845880b0f90vboxsync * When distributing Covered Software, include this CDDL Header Notice in each file and include
c55c68b6a3324172e9dc207926215845880b0f90vboxsync * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
c55c68b6a3324172e9dc207926215845880b0f90vboxsync * Header, with the fields enclosed by brackets [] replaced by your own identifying
c55c68b6a3324172e9dc207926215845880b0f90vboxsync * information: "Portions copyright [year] [name of copyright owner]".
c55c68b6a3324172e9dc207926215845880b0f90vboxsync *
c55c68b6a3324172e9dc207926215845880b0f90vboxsync * Copyright 2016 ForgeRock AS.
c55c68b6a3324172e9dc207926215845880b0f90vboxsync *
59190ecd61435d19ba3515b876272aee7bd12298vboxsync * Portions Copyright 2014 Nathaniel McCallum, Red Hat
59190ecd61435d19ba3515b876272aee7bd12298vboxsync */
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync#import "URLImageView.h"
59190ecd61435d19ba3515b876272aee7bd12298vboxsync#import <AssetsLibrary/AssetsLibrary.h>
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync@implementation URLImageView
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync- (void)setUrl:(NSURL *)url {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync _url = url;
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync if (url.isFileURL) {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync self.image = [UIImage imageWithContentsOfFile:url.path];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync return;
59190ecd61435d19ba3515b876272aee7bd12298vboxsync }
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync if ([url.scheme isEqualToString:@"assets-library"]) {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync ALAssetsLibrary* al = [[ALAssetsLibrary alloc] init];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync [al assetForURL:url
59190ecd61435d19ba3515b876272aee7bd12298vboxsync resultBlock:^(ALAsset *asset) {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync ALAssetRepresentation *rep = [asset defaultRepresentation];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync @autoreleasepool {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync CGImageRef iref = [rep fullScreenImage];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync if (iref) {
59190ecd61435d19ba3515b876272aee7bd12298vboxsync UIImage *image = [UIImage imageWithCGImage:iref];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync self.image = image;
59190ecd61435d19ba3515b876272aee7bd12298vboxsync iref = nil;
59190ecd61435d19ba3515b876272aee7bd12298vboxsync }
59190ecd61435d19ba3515b876272aee7bd12298vboxsync }
59190ecd61435d19ba3515b876272aee7bd12298vboxsync }
59190ecd61435d19ba3515b876272aee7bd12298vboxsync failureBlock:nil];
59190ecd61435d19ba3515b876272aee7bd12298vboxsync return;
59190ecd61435d19ba3515b876272aee7bd12298vboxsync }
59190ecd61435d19ba3515b876272aee7bd12298vboxsync}
59190ecd61435d19ba3515b876272aee7bd12298vboxsync
59190ecd61435d19ba3515b876272aee7bd12298vboxsync@end
59190ecd61435d19ba3515b876272aee7bd12298vboxsync