Skip to content

Commit

Permalink
Merge pull request AFNetworking#3229 from lessthanyouthink/fix-watchO…
Browse files Browse the repository at this point in the history
…S-image-response-serialization

Fixed `AFImageResponseSerializer` serializing on watchOS
  • Loading branch information
kcharwood committed Dec 16, 2015
2 parents 151da22 + 75d83fd commit 73df7b9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions AFNetworking/AFURLResponseSerialization.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ - (instancetype)copyWithZone:(NSZone *)zone {

#pragma mark -

#if TARGET_OS_IOS || TARGET_OS_TV
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>

Expand Down Expand Up @@ -670,10 +670,10 @@ - (instancetype)init {

self.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];

#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_TV
self.imageScale = [[UIScreen mainScreen] scale];
self.automaticallyInflatesResponseImage = YES;
#elif TARGET_OS_WATCH
#elif TARGET_OS_WATCH
self.imageScale = [[WKInterfaceDevice currentDevice] screenScale];
self.automaticallyInflatesResponseImage = YES;
#endif
Expand All @@ -693,13 +693,13 @@ - (id)responseObjectForResponse:(NSURLResponse *)response
}
}

#if TARGET_OS_IOS || TARGET_OS_TV
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
if (self.automaticallyInflatesResponseImage) {
return AFInflatedImageFromResponseWithDataAtScale((NSHTTPURLResponse *)response, data, self.imageScale);
} else {
return AFImageWithDataAtScale(data, self.imageScale);
}
#elif !TARGET_OS_WATCH
#else
// Ensure that the image is set to it's correct pixel width and height
NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:data];
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])];
Expand All @@ -719,7 +719,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder {
return nil;
}

#if TARGET_OS_IOS || TARGET_OS_TV
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
NSNumber *imageScale = [decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(imageScale))];
#if CGFLOAT_IS_DOUBLE
self.imageScale = [imageScale doubleValue];
Expand All @@ -736,7 +736,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder {
- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];

#if TARGET_OS_IOS || TARGET_OS_TV
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
[coder encodeObject:@(self.imageScale) forKey:NSStringFromSelector(@selector(imageScale))];
[coder encodeBool:self.automaticallyInflatesResponseImage forKey:NSStringFromSelector(@selector(automaticallyInflatesResponseImage))];
#endif
Expand All @@ -747,7 +747,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
- (instancetype)copyWithZone:(NSZone *)zone {
AFImageResponseSerializer *serializer = [[[self class] allocWithZone:zone] init];

#if TARGET_OS_IOS || TARGET_OS_TV
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
serializer.imageScale = self.imageScale;
serializer.automaticallyInflatesResponseImage = self.automaticallyInflatesResponseImage;
#endif
Expand Down

0 comments on commit 73df7b9

Please sign in to comment.