CGImageSourceCreateWithURL与认证 [英] CGImageSourceCreateWithURL with authentication

查看:577
本文介绍了CGImageSourceCreateWithURL与认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从URL中读取图像特性,如:

i'm trying to read image property from a url like :

http://www.example.com/ws/img/8

由于这是一个Web服务,我需要通过身份验证的URL。 我不想下载的图片看它的属性,所以我试图用CGImageSourceCreateWithURL这样的:

As it's a webservice, i need to pass authentication to URL. I don't want to download the image to read it's properties. So i'm trying to use CGImageSourceCreateWithURL like this:

CGImageSourceRef imageSourceRef = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL URLWithString:@"http://admin:admin@www.example.com/ws/img/8"], NULL);
CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(imageSourceRef, 0, NULL);

道具还是返回null。

是否与验证,以访问图片属性的方法吗?
(如果我通过RestKit功能下载图像,它的作品当然)

Is there a way to access image properties with authentication? (If i download image through RestKit function, it works of course)

感谢

推荐答案

而不是使用 CGImageSourceCreateWithURL ,我会用一个<一个href=\"https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html\"相对=nofollow> 的NSURLRequest ,提供相应的身份验证并下载图像作为的NSData ,然后使用<一个href=\"https://developer.apple.com/library/ios/documentation/graphicsimaging/Reference/CGImageSource/Reference/reference.html#//apple_ref/c/func/CGImageSourceCreateWithData\"相对=nofollow> CGImageSourceCreateWithData ,或者只是下载图像与RestKit如果已经工作。

Rather than using CGImageSourceCreateWithURL, I would use an NSURLRequest with the appropriate authentication and download the image as an NSData and then use CGImageSourceCreateWithData, or just download the image with RestKit if that already works.

这将允许您在身份验证协议的更多的灵活性。该withURL初始化实际上就是如果你做不添加所需的信息的基本HTTP GET效用函数。

This will allow you a lot more flexibility in authenticate protocols. The withURL initializer is really just a utility function if you're doing a basic HTTP GET without added information required.

这篇关于CGImageSourceCreateWithURL与认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆