//
//  UIImage+GMloadImage.m
//  Gengmei
//
//  Created by 刘鹿杰的mac on 2019/5/6.
//  Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//

#import "UIImage+GMloadImage.h"

@implementation UIImage (GMloadImage)

+ (UIImage *)loadOriginalImageWithString:(id )string{
    UIImage* image = nil;
    if ([string isKindOfClass:[UIImage class]]){
        image = (UIImage *)string;
    } else if ([string isKindOfClass:[NSString class]]) {
        NSString *url = (NSString *)string;
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.5];
        NSURLResponse *response = nil;
        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
        image = [UIImage imageWithData: data];
        //如果远程的图片下载不下来，则使用默认图
        if (image == nil) {
            image = [UIImage imageNamed:@"icon"];
        }
    }
    return image;
}

@end
