如何在应用扩展程序中从URL加载图像?

时间:2021-07-19 23:09:35

I have implemented an app extension for my application, but i am facing an issue when trying to load an image from a URL into an imageView. I tried to use PAImageView and UIImageView but both with failure.

我已经为我的应用程序实现了应用程序扩展,但是当我尝试将图像从URL加载到imageView时,我遇到了一个问题。我尝试使用PAImageView和UIImageView,但都失败了。

The code that i was using for PAImageView is the following:

我用于PAImageView的代码如下:

[self.imageView setImageURL:[NSURL URLWithString:@"https://blabblaLogo.jpg"]];
          self.userImageView.clipsToBounds = YES;

and tried to use SDWebImage for UIImageView with the following:

并尝试使用SDWebImage for UIImageView,具体如下:

 [self.imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"default.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
        }];

and the image doesnt appear in both cases. Note that a default image from assets is displayed correctly without any issue.

并且在两种情况下都不会出现图像。请注意,资产中的默认图像显示正确,没有任何问题。

Is it possible to load an image from a URL in an app Extension? and how can we achieve that?

是否可以从应用扩展程序中的URL加载图像?我们怎样才能做到这一点?

Thank you.

3 个解决方案

#1


0  

Am using something like this and it's work good until this issues fixed

我使用这样的东西,并且在这个问题得到修复之前它的工作正常

cell.avatar.image = [UIImage imageNamed:@"selection-box_emty.png"];

cell.avatar.image = [UIImage imageNamed:@“selection-box_emty.png”];

// Load the image with an GCD block executed in another thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:Arr[indexPath.row][@"avatar"]]];

    if (data) {
        UIImage *offersImage = [UIImage imageWithData:data];
        if (offersImage) {
            dispatch_async(dispatch_get_main_queue(), ^{

                UIImage *offersImage = [UIImage imageWithData:data];

                cell.avatar.image = offersImage;
            });
        }
    }
});

#2


0  

I faced a similar problem, put breakpoints into into library and problem apparently was App Tranport Security. We need separate App Transport Security Settings for every extension we add

我遇到了类似的问题,将断点放入库中,问题显然是App Tranport Security。对于我们添加的每个扩展,我们都需要单独的App Transport Security设置

#3


0  

Try This in your Image url

在你的图片网址中试试这个

If image url contain any space it will add %20 and work fine

如果图片网址包含任何空格,则会添加%20并正常工作

[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

#1


0  

Am using something like this and it's work good until this issues fixed

我使用这样的东西,并且在这个问题得到修复之前它的工作正常

cell.avatar.image = [UIImage imageNamed:@"selection-box_emty.png"];

cell.avatar.image = [UIImage imageNamed:@“selection-box_emty.png”];

// Load the image with an GCD block executed in another thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:Arr[indexPath.row][@"avatar"]]];

    if (data) {
        UIImage *offersImage = [UIImage imageWithData:data];
        if (offersImage) {
            dispatch_async(dispatch_get_main_queue(), ^{

                UIImage *offersImage = [UIImage imageWithData:data];

                cell.avatar.image = offersImage;
            });
        }
    }
});

#2


0  

I faced a similar problem, put breakpoints into into library and problem apparently was App Tranport Security. We need separate App Transport Security Settings for every extension we add

我遇到了类似的问题,将断点放入库中,问题显然是App Tranport Security。对于我们添加的每个扩展,我们都需要单独的App Transport Security设置

#3


0  

Try This in your Image url

在你的图片网址中试试这个

If image url contain any space it will add %20 and work fine

如果图片网址包含任何空格,则会添加%20并正常工作

[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];