错误域= NSURLErrorDomain代码= 403"操作无法完成。 (NSURLErrorDomain错误403。)"

时间:2016-10-20 04:47:51

标签: ios objective-c back4app

我正在使用sdwebimage和back4app后端。我们无法从back4app加载图片。

 [immg1 sd_setImageWithURL:url11 placeholderImage:[UIImage imageNamed:@"pro"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                if (error)
                {
                    NSLog(@"B4A_Error: %@", error.localizedDescription);
                    NSLog(@"B4A_Error URL: %@", imageURL.absoluteString);

                }
                else
                {
                    NSLog (@"B4A_Success");
                    [immg1 setNeedsDisplay];
                }
            }];


//            [immg1 setImageWithURL:url11 usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];


           [imgView addSubview:immg1];

1 个答案:

答案 0 :(得分:0)

由于某些原因,您的SDWebImage没有保留user-Agent。我在每次通话前手动强制它持续存在。试试这个:

 NSString *userAgent = @"";
            userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];

            if (userAgent) {
                if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
                    NSMutableString *mutableUserAgent = [userAgent mutableCopy];
                    if (CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, (__bridge CFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove", false)) {
                        userAgent = mutableUserAgent;
                    }
                }
                [[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];
            }
相关问题