问题一:从附件下载下来的图片,服务端返回字节流,客户端处理后怎么都不显示,有时候还报如下问题
"-[__NSCFString bytes]: unrecognized selector sent to instance"
1、正常字符串转NSData:
NSData *imageData =[data dataUsingEncoding:NSUTF8StringEncoding];
这种方法解析后,程序没有crash,但是图片不显示。
2、看下返回的data数据如下:
"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAHCAlgDASIAAhEBAxEB/8QAHwAAAQUBAQEBA......."
看着像base64的编码。
所以如下转换:
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:data options:0];
转化后,终于显示出来了。
问题二:The file “XXX” couldn’t be opened because you don’t have permission to view it.
在模拟器运行,忽然xcode报这个错误
解决方法:删除缓存DerivedData文件夹
1、先找到DerivedData在哪里
xcode—preferences—source control
删除之后,重新运行就ok了。
问题三:使用QBImagePickerController第三方,选择多张图片后,回到当前ViewController中,经常提示“ALAssetPrivate past the lifetime of its owning ALAssetsLibrary”,说是ALAssetsLibrary它的生命周期失效了。用网上的说是要将ALAssetsLibrary单列实例化,但是在读取相册图片时,还未用到ALAssetsLibrary,只是在拍照片的时候用到了。
从相册选取照片,是将相关信息存在model中的
@property(nonatomic,strong)id image; //原图, PHAsset/ALAsset
model中用这个字段来存放ALAsset。由于要兼容7.x的系统,此处用ALAsset。
等到要上传的时候,打印出来的image为空,提示“ALAssetPrivate past the lifetime of its owning ALAssetsLibrary”这个错误。
如下解决方案:
////获取高清图片
ALAssetRepresentation *options = [asset defaultRepresentation];
[assetslibrary assetForURL:options.url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *representation = [asset defaultRepresentation];
//获取缩略图
CGImageRef ref = [asset thumbnail];
UIImage *thumbnailImg = [[UIImage alloc]initWithCGImage:ref];
PhotoModel *model = [[PhotoModel alloc] init];
model.thumb = thumbnailImg;
model.image = asset;
model.size = [weakSelf getSizeDescription:[representation size]];
model.localImg = YES;
} failureBlock:^(NSError *error) {
NSLog(@"fall--->%@",error);
}];
问题四:
Failed to chmod /Users/XXXX/Library/Developer/CoreSimulator/Devices/5CA4EC14-8444-4FD7-89CE-8A8D52B82A05/data/Library/Caches/com.apple.containermanagerd/Bundle/Application/D5CE06BC-C34C-4738-A7D2-C35B30057228/SPBDPerformanceManagement.app/SPBDPerformanceManagement : No such file or directory
模拟器之前运行的好好的 突然出现如上错误,解决方案,就是重启模拟器,搞定!