專案中遇到的坑~
問題一:從附件下載下來的圖片,服務端返回位元組流,客戶端處理後怎麼都不顯示,有時候還報如下問題
"-[__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
模擬器之前執行的好好的 突然出現如上錯誤,解決方案,就是重啟模擬器,搞定!