Getting Image from URL Objective C

前端 未结 5 1786
甜味超标
甜味超标 2020-12-04 08:13

I\'m trying to get an image from an URL and it doesn\'t seem to be working for me. Can someone point me in the right direction?

Here is my code:

NSUR         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 08:31

    Updating upon Jim dovey answer,[data release] is no longer required because in the updated apple guidelines. Memory management is done automatically by ARC (Automatic counting reference) ,

    Here is the updated asynchronous call,

    dispatch_async(dispatch_get_global_queue(0,0), ^{
            NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"your_URL"]];
            if ( data == nil )
                return;
            dispatch_async(dispatch_get_main_queue(), ^{
                self.your_UIimage.image = [UIImage imageWithData: data];
            });
    
        });
    

提交回复
热议问题