SDImageCache - unrecognized selector error after 4.0 migration - ios

I recently upgraded a project to SDWebImage 4.0, which I'm only using to cache images and later retrieve them. Had this working flawlessly on the 3.x version. I'm now getting the following error after migrating...
-[SDImageCache storeImage:forKey:toDisk:completion:]: unrecognized selector sent to instance 0x174097cf0
This seems like it should be a simple error to resolve, but after multiple attempts, I'm unable to fix it.
Here is my previous code from the 3.x API...
#property (strong, nonatomic) SDImageCache *imageCache;
- (SDImageCache *)imageCache {
if (!_imageCache) {
_imageCache = [[SDImageCache alloc] initWithNamespace:NAME_SPACE_IMAGE_CACHE];
}
return _imageCache;
}
[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES];
Here is my updated code for the 4.0 API, which is the line of code throwing the error...
[self.imageCache storeImage:[UIImage imageWithContentsOfFile:imageData.imageURL.path] forKey:imageData.imageURL.absoluteString toDisk:YES completion:^{
NSLog(#"INFO: Image cached successfully!");
}];
Could someone please help clarify what the issue is?
Thanks in advance!

I try like this and it works, you must shift + cmd + k and build again, must solve the problem as is pointed out here https://github.com/rs/SDWebImage/issues/1602
#import "ViewController.h"
#interface ViewController ()
#property SDImageCache * imageCache;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imageCache = [SDWebImageManager sharedManager].imageCache;
// Do any additional setup after loading the view, typically from a nib.
[_imageCache storeImage:[UIImage imageNamed:#"test"] forKey:#"testKey" toDisk:YES completion:^{
NSLog(#"INFO: Image cached successfully!");
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
CONSOLE OUTPUT
2017-07-11 00:55:12.146 SDWebImageSOQuestion[17275:339149] INFO: Image
cached successfully!
Hope this helps

I had the same issue when my pod updated to 5.0. To fix it I needed to...
Change
[imageCache clearDisk];
To
[imageCache clearDiskOnCompletion:^{
}];

Related

pebbleCentral:watchDidConnect never gets called on iOS

I have an old Pebble Classic watch, upgraded to latest firmware (3.8.2) and using latest Pebble-SDK.
I have followed the few simple steps to install SDK, setup an Xcode project and adding the code to initialise and connect:
https://developer.getpebble.com/guides/mobile-apps/ios/
My problem is, that the delegate method pebbleCentral:watchDidConnect never gets called!
I am using the Pebble Time app on the iPad to install the watchApp in the watch, so I know the iPad is connected to the watch. The same iPad runs the iOS app, which apparently does not discover the watch.
I have tried to import an old test project from a colleague, who had it running a year or two ago. Same watch, same watchApp, but of course older firmware and SDK versions. Same result...
I think the documentation on the pebble site is quite simple and easy to follow. However, I feel I am missing some explanations of how and when this watchDidConnect is supposed to be triggered.
I am most likely missing some simple step somewhere, but I am quite lost in where to look!
Any ideas are welcome!
EDIT: My code looks like this:
ViewController.h:
#import <UIKit/UIKit.h>
#import PebbleKit;
#interface ViewController : UIViewController<PBPebbleCentralDelegate>
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) PBWatch* connectedWatch;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[PBPebbleCentral defaultCentral].delegate = self;
[[PBPebbleCentral defaultCentral] run];
NSLog(#"Pebble initialised");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidConnect (PBWatch*)watch isNew:(BOOL)isNew {
NSLog(#"Pebble connected: %#", [watch name]);
self.connectedWatch = watch;
}
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidDisconnect:(PBWatch*)watch {
NSLog(#"Pebble disconnected: %#", [watch name]);
if ([watch isEqual:self.connectedWatch]) {
self.connectedWatch = nil;
}
}
#end
Are you calling the -run method, after setting up your Pebble central? I noticed that the code snippet in the link you posted does not show the central's delegate being set.
[PBPebbleCentral defaultCentral].delegate = self; // Set your delegate
[PBPebbleCentral defaultCentral].appUUID = [[NSUUID alloc] initWithUUIDString:#"Your Pebble App UUID"]; // Set the app UUID
[[PBPebbleCentral defaultCentral] run]; // Call -run on the central

How do I get cached image stored by AFNetworking's UIImageView category?

I'm using following category UIImageView+AFNetworking.h from AFNetworking in my app, its working fine, its caching photos for me and loads images smoothly.
At one point, I want to get an image which is already there in my cache.
So I dig up into above category class where I found following code, which I think – can be helpful.
Here's the snippet from it:
#implementation AFImageCache
- (UIImage *)cachedImageForRequest:(NSURLRequest *)request {
switch ([request cachePolicy]) {
case NSURLRequestReloadIgnoringCacheData:
case NSURLRequestReloadIgnoringLocalAndRemoteCacheData:
return nil;
default:
break;
}
return [self objectForKey:AFImageCacheKeyFromURLRequest(request)];
}
- (void)cacheImage:(UIImage *)image
forRequest:(NSURLRequest *)request
{
if (image && request) {
[self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)];
}
}
#end
If you want me to add web version of this, it's already here.
I think, - (UIImage *)cachedImageForRequest:(NSURLRequest *)request is the method which can return me my cached image.
But I'm not sure, how can I use it?
If I know Objective-C a bit, it's a kinda a "protocol"?
What I have tried so far is to use it like a protocol in one of my view controller. Like this:
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController<AFImageCache>
#end
But then it is giving me following warnings:
I'm not sure how to resolve those warnings and get the image from cache? Or any other more appropriate way?
I assume you import UIImageView+AFNetworking.h header.
If you want to access to the cached image. You should have a NSURLRequest object. Then it is like this:
UIImage *image = [[UIImageView sharedImageCache] cachedImageForRequest:request];
Done!

watch kit extension connect using SQLite

I need help how to connect my SQLite database to my watchkit app extension. Im not much familiar in using sqlite with cell rows. Any easy sample codes will be a great help thanks. Below are sample arrays i used for example.
#import "ICBQuoteSource.h"
#implementation ICBQuoteSource
+(NSArray *)quoteDictionary {
NSMutableArray *quotes = [NSMutableArray new];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"I came here to drink milk and kick ass... and I've just finished my milk."}];
[quotes addObject:#{#"characterImage": #"roy", #"characterName": #"Roy", #"quote": #"Hello, IT, have you tried turning it off and on again?"}];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"Did you see that ludicrous display last night?"}];
[quotes addObject:#{#"characterImage": #"denholm", #"characterName": #"Denholm", #"quote": #"That's the sort of place this is, Jen. A lot of sexy people not doing much work and having affairs."}];
[quotes addObject:#{#"characterImage": #"moss", #"characterName": #"Moss", #"quote": #"This Jen is the Internet"}];
return [NSArray arrayWithArray:quotes];
}
#end
#import "InterfaceController.h"
#import "ICBQuoteSource.h"
#import "rowController.h"
#interface InterfaceController()
#property (nonatomic, strong) NSArray *quotes;
#end
#implementation InterfaceController
- (void)awakeWithContext:(id)context
{
[super awakeWithContext:context];
// Get quotes
self.quotes = [ICBQuoteSource quoteDictionary];
// Set number of table Row
[self.table setNumberOfRows:self.quotes.count withRowType:#"Row Controller"];
// Set row properties
for (NSDictionary *quote in self.quotes) {
rowController *quoteRow = [self.table rowControllerAtIndex:[self.quotes indexOfObject:quote]];
[quoteRow.englishTxtLabel setText:quote[#"characterName"]];
[quoteRow.translationTxtLabel setText:quote[#"quote"]];
}
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
#end
You haven't actually stated what the problem is...so let me attempt to guess. I'm assuming that the rows are not showing up properly in your table. What I would suggest trying is moving your row set up logic into willActivate. This is something I found when working with tables in Xcode 6.2b5. You would not get the appropriate behavior in awakeWithContext(:).
Hopefully that helps lead you in the right direction. If this isn't the actual problem you are having, then please edit your question and I'll edit my answer accordingly.

GPUImage failing the CVPixelBufferGetPlaneCount check on iOS

I'm currently bringing a legacy project up from iOS 5/6 to iOS 6/7.
Part of this project involves taking a picture using the GPUImage library, processing it with a crop filter, then optionally adding some saturation and blur effects. I am currently using version 0.1.2 installed via cocoa pods.
The problem I am having is that when I try to capture an image from the camera, I hit the following assert in GPUImageStillCamera.m line 254
if (CVPixelBufferGetPlaneCount(cameraFrame) > 0)
{
NSAssert(NO, #"Error: no downsampling for YUV input in the framework yet");
}
where cameraFrame is a CVImageBufferRef
I have reproduced the code where this is called and move it to another project, where it works perfectly.
Once I moved this reproduced class back into the main project, I was hitting the assert every time.
Things I've ruled out with my own debugging
64bit (it’s happening on both)
different lib version
initial object setup / code / usage
This has lead me to believe that perhaps it might be a project setting that I've over looked. Any help or even a pointer in the right direction would be very very welcome. I've spent a good 1-2 days on this now and am still entirely lost!
I've included the stripped down class below which shows the general use.
#import "ViewController.h"
#import "GPUImage.h"
#import "ImageViewController.h"
#interface ViewController ()
#property (nonatomic, strong) IBOutlet GPUImageView *gpuImageView;
#property (nonatomic, strong) GPUImageStillCamera *camera;
#property (nonatomic, strong) GPUImageCropFilter *cropFilter;
#end
#implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setupCameraCapture];
}
- (void)setupCameraCapture
{
if (self.camera) {
return;
}
self.cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0, 1, 0.5625)];
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
self.camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];
}
else {
self.camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionFront];
}
self.camera.outputImageOrientation = UIInterfaceOrientationPortrait;
NSError *error = nil;
[self.camera.inputCamera lockForConfiguration:&error];
[self.camera.inputCamera setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[self.camera.inputCamera setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
if ([self.camera.inputCamera respondsToSelector:#selector(isLowLightBoostSupported)]) {
BOOL isSupported = self.camera.inputCamera.isLowLightBoostSupported;
if (isSupported) {
[self.camera.inputCamera setAutomaticallyEnablesLowLightBoostWhenAvailable:YES];
}
}
[self.camera.inputCamera unlockForConfiguration];
[self.camera addTarget:self.cropFilter];
[self.cropFilter addTarget:self.gpuImageView];
[self.camera startCameraCapture];
}
- (IBAction)capturePressed:(id)sender
{
[self.camera capturePhotoAsImageProcessedUpToFilter:self.cropFilter withCompletionHandler:^(UIImage *image, NSError *error) {
// do something with the image here
}];
}
#end
The actual culprit was a swizzled method found by my colleague Marek. Hidden away in the depths of the old codebase. The above code works fine.
Lesson: if you really have to swizzle something, make sure you leave proper documentation for the future devs.

JMImageCache in a simple test app crashes with EXC_BAD_ACCESS

In Xcode 5.0.2
I create a blank single view app for iPhone,
then add a "male.png" image to the project,
drag a UIImageView to the storyboard
and finally add the following code to the viewDidLoad:
_imageView.image = [UIImage imageNamed:#"male.png"];
This works well:
Then I add the 4 files from JMImageCache project and change the ViewController.m to:
#import "ViewController.h"
#import "JMImageCache.h"
static NSString* const kAvatar = #"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
placeholder:[UIImage imageNamed:#"male.png"]];
}
#end
Unfortunately, this results in app crash with the error message Thread 1: EXC_BAD_ACCESS:
At his webpage Jake Marsh (the author of JMImageCache) notes:
JMImageCache purposefully uses NSString objects instead of NSURL's to make things easier and cut down on [NSURL URLWithString:#"..."] bits everywhere. Just something to notice in case you see any strange EXC_BAD_ACCESS exceptions, make sure you're passing in NSString's and not NSURL's.
But (as an iOS programming newbie) I don't understand, what exactly does Mr. Marsh mean - since his file UIImageView+JMImageCache.m declares the 1st argument for the public method as NSURL:
- (void) setImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholderImage {
[self setImageWithURL:url key:nil placeholder:placeholderImage];
}
Is the note maybe outdated and how could I fix my app?
That's a bug in JMImageCache. setImageWithURL:key:placeholder:completionBlock: calls itself, exhausting the stack.
To work around the bug, call the longer form of the method:
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
key:nil
placeholder:[UIImage imageNamed:#"male.png"]
completionBlock:nil
failureBlock:nil];
Or, use an older version of the library (e.g. 0.4.0). Looks like the bug was introduced in 1af09be78a.

Resources