ios - dataWithContentsOfURL 取有些图片返回空?
伊谢尔伦
伊谢尔伦 2017-04-18 09:57:16
[iOS讨论组]

使用dataWithContentsOfURL方法取图片文件,有些返回nil,例如:

NSURL *url=[NSURL URLWithString:@"http://wx2.sinaimg.cn/mw690/6f250299gy1fefknh4ml6j21kw163gyj.jpg"];
NSData *data=[NSData dataWithContentsOfURL:url options:nil error:&error];

图是微博里随便找的,直接在浏览器可以打开;执行后data为nil,Error如下:

Error Domain=NSCocoaErrorDomain Code=256 "The file “6f250299gy1fefknh4ml6j21kw163gyj.jpg” couldn’t be opened." UserInfo={NSURL=http://wx2.sinaimg.cn/mw690/6...}

同样的使用方法,换成其他比如百度Logo图片:

NSURL *url=[NSURL URLWithString:@"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png"];
NSData *data=[NSData dataWithContentsOfURL:url options:nil error:&error];

结果正常。求问怎么回事?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号