Commit 013213a2 authored by AvatarC's avatar AvatarC

添加友盟统计

parent 1a474ed0
...@@ -7,4 +7,5 @@ pod 'SDWebImage' ...@@ -7,4 +7,5 @@ pod 'SDWebImage'
pod 'MBProgressHUD' pod 'MBProgressHUD'
pod 'MJRefresh' pod 'MJRefresh'
pod 'RATreeView' pod 'RATreeView'
pod 'JPushSDK', '~> 1.8.2' pod 'JPushSDK', '~> 1.8.2'
\ No newline at end of file pod 'UMengAnalytics'
\ No newline at end of file
...@@ -22,11 +22,12 @@ PODS: ...@@ -22,11 +22,12 @@ PODS:
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- JPushSDK (1.8.2) - JPushSDK (1.8.2)
- MBProgressHUD (0.9.2) - MBProgressHUD (0.9.2)
- MJRefresh (3.1.0) - MJRefresh (3.0.8)
- RATreeView (2.1.0) - RATreeView (2.1.0)
- SDWebImage (3.7.5): - SDWebImage (3.7.3):
- SDWebImage/Core (= 3.7.5) - SDWebImage/Core (= 3.7.3)
- SDWebImage/Core (3.7.5) - SDWebImage/Core (3.7.3)
- UMengAnalytics (3.6.6)
DEPENDENCIES: DEPENDENCIES:
- AFNetworking (~> 2.0) - AFNetworking (~> 2.0)
...@@ -35,13 +36,15 @@ DEPENDENCIES: ...@@ -35,13 +36,15 @@ DEPENDENCIES:
- MJRefresh - MJRefresh
- RATreeView - RATreeView
- SDWebImage - SDWebImage
- UMengAnalytics
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60 AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60
JPushSDK: c68dd04c595a5c93aa003f212974010790410d8e JPushSDK: c68dd04c595a5c93aa003f212974010790410d8e
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1 MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
MJRefresh: 743e6404967d1c2c688472ea3ecfde247d872db4 MJRefresh: fafde8f18f4afd66b434331a9beb67a6c0264056
RATreeView: fc82ec26b8be18cfa0f5f99a5abbe6be68edb21f RATreeView: fc82ec26b8be18cfa0f5f99a5abbe6be68edb21f
SDWebImage: 69c6303e3348fba97e03f65d65d4fbc26740f461 SDWebImage: 1d2b1a1efda1ade1b00b6f8498865f8ddedc8a84
UMengAnalytics: 4bf831415146b9c57cb10be65fbd43462ef8cf65
COCOAPODS: 0.39.0 COCOAPODS: 0.39.0
...@@ -22,11 +22,12 @@ PODS: ...@@ -22,11 +22,12 @@ PODS:
- AFNetworking/NSURLSession - AFNetworking/NSURLSession
- JPushSDK (1.8.2) - JPushSDK (1.8.2)
- MBProgressHUD (0.9.2) - MBProgressHUD (0.9.2)
- MJRefresh (3.1.0) - MJRefresh (3.0.8)
- RATreeView (2.1.0) - RATreeView (2.1.0)
- SDWebImage (3.7.5): - SDWebImage (3.7.3):
- SDWebImage/Core (= 3.7.5) - SDWebImage/Core (= 3.7.3)
- SDWebImage/Core (3.7.5) - SDWebImage/Core (3.7.3)
- UMengAnalytics (3.6.6)
DEPENDENCIES: DEPENDENCIES:
- AFNetworking (~> 2.0) - AFNetworking (~> 2.0)
...@@ -35,13 +36,15 @@ DEPENDENCIES: ...@@ -35,13 +36,15 @@ DEPENDENCIES:
- MJRefresh - MJRefresh
- RATreeView - RATreeView
- SDWebImage - SDWebImage
- UMengAnalytics
SPEC CHECKSUMS: SPEC CHECKSUMS:
AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60 AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60
JPushSDK: c68dd04c595a5c93aa003f212974010790410d8e JPushSDK: c68dd04c595a5c93aa003f212974010790410d8e
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1 MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
MJRefresh: 743e6404967d1c2c688472ea3ecfde247d872db4 MJRefresh: fafde8f18f4afd66b434331a9beb67a6c0264056
RATreeView: fc82ec26b8be18cfa0f5f99a5abbe6be68edb21f RATreeView: fc82ec26b8be18cfa0f5f99a5abbe6be68edb21f
SDWebImage: 69c6303e3348fba97e03f65d65d4fbc26740f461 SDWebImage: 1d2b1a1efda1ade1b00b6f8498865f8ddedc8a84
UMengAnalytics: 4bf831415146b9c57cb10be65fbd43462ef8cf65
COCOAPODS: 0.39.0 COCOAPODS: 0.39.0
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -12,7 +12,7 @@ This library provides a category for UIImageView with support for remote images ...@@ -12,7 +12,7 @@ This library provides a category for UIImageView with support for remote images
It provides: It provides:
- An `UIImageView` category adding web image and cache management to the Cocoa Touch framework - An UIImageView category adding web image and cache management to the Cocoa Touch framework
- An asynchronous image downloader - An asynchronous image downloader
- An asynchronous memory + disk image caching with automatic cache expiration handling - An asynchronous memory + disk image caching with automatic cache expiration handling
- Animated GIF support - Animated GIF support
...@@ -26,7 +26,7 @@ It provides: ...@@ -26,7 +26,7 @@ It provides:
- Arm64 support - Arm64 support
NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.1.1 NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.1.1
minimum deployment version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat). minimum deployement version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).
[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F) [How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)
...@@ -51,11 +51,14 @@ handled for you, from async downloads to caching management. ...@@ -51,11 +51,14 @@ handled for you, from async downloads to caching management.
... ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier"; static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease]; reuseIdentifier:MyIdentifier] autorelease];
} }
...@@ -71,16 +74,14 @@ handled for you, from async downloads to caching management. ...@@ -71,16 +74,14 @@ handled for you, from async downloads to caching management.
### Using blocks ### Using blocks
With blocks, you can be notified about the image download progress and whenever the image retrieval With blocks, you can be notified about the image download progress and whenever the image retrival
has completed with success or not: has completed with success or not:
```objective-c ```objective-c
// Here we use the new provided sd_setImageWithURL: method to load the web image // Here we use the new provided sd_setImageWithURL: method to load the web image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {... completion code here ...}];
... completion code here ...
}];
``` ```
Note: neither your success nor failure block will be call if your image request is canceled before completion. Note: neither your success nor failure block will be call if your image request is canceled before completion.
...@@ -112,17 +113,19 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; ...@@ -112,17 +113,19 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
It's also possible to use the async image downloader independently: It's also possible to use the async image downloader independently:
```objective-c ```objective-c
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; [SDWebImageDownloader.sharedDownloader downloadImageWithURL:imageURL
[downloader downloadImageWithURL:imageURL options:0
options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize)
progress:^(NSInteger receivedSize, NSInteger expectedSize) { {
// progression tracking code // progression tracking code
} }
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
if (image && finished) { {
// do something with image if (image && finished)
} {
}]; // do something with image
}
}];
``` ```
### Using Asynchronous Image Caching Independently ### Using Asynchronous Image Caching Independently
...@@ -141,7 +144,8 @@ the image. ...@@ -141,7 +144,8 @@ the image.
```objective-c ```objective-c
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"]; SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image) { [imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image)
{
// image is not nil if image was found // image is not nil if image was found
}]; }];
``` ```
...@@ -169,7 +173,8 @@ The following example sets a filter in the application delegate that will remove ...@@ -169,7 +173,8 @@ The following example sets a filter in the application delegate that will remove
the URL before to use it as a cache key: the URL before to use it as a cache key:
```objective-c ```objective-c
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) { SDWebImageManager.sharedManager.cacheKeyFilter = ^(NSURL *url) {
url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
return [url absoluteString]; return [url absoluteString];
...@@ -227,24 +232,9 @@ platform :ios, '6.1' ...@@ -227,24 +232,9 @@ platform :ios, '6.1'
pod 'SDWebImage', '~>3.7' pod 'SDWebImage', '~>3.7'
``` ```
If you are using Swift, be sure to add `use_frameworks!` and set your target to iOS 8+:
```
platform :ios, '8.0'
use_frameworks!
```
#### Subspecs
There are 3 subspecs available now: `Core`, `MapKit` and `WebP` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `WebP`, you need to specify it).
Podfile example:
```
pod 'SDWebImage/WebP'
```
### Installation with Carthage (iOS 8+) ### Installation with Carthage (iOS 8+)
[Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods. [Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and ins less invasive than CocoaPods.
To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage) To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage)
...@@ -256,14 +246,9 @@ github "rs/SDWebImage" ...@@ -256,14 +246,9 @@ github "rs/SDWebImage"
#### Usage #### Usage
Swift Swift
If you installed using CocoaPods:
```
import SDWebImage
```
If you installed manually:
``` ```
import WebImage import WebImage
``` ```
Objective-C Objective-C
...@@ -306,10 +291,6 @@ If you're using Cocoa Pods and have any frameworks that extend optional librarie ...@@ -306,10 +291,6 @@ If you're using Cocoa Pods and have any frameworks that extend optional librarie
``` ```
-force_load $(TARGET_BUILD_DIR)/libPods.a -force_load $(TARGET_BUILD_DIR)/libPods.a
``` ```
and this:
```
$(inherited)
```
### Import headers in your source files ### Import headers in your source files
......
...@@ -37,21 +37,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot ...@@ -37,21 +37,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
@interface SDImageCache : NSObject @interface SDImageCache : NSObject
/** /**
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. * Decompressing images that are downloaded and cached can improve peformance but can consume lot of memory.
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
*/ */
@property (assign, nonatomic) BOOL shouldDecompressImages; @property (assign, nonatomic) BOOL shouldDecompressImages;
/**
* disable iCloud backup [defaults to YES]
*/
@property (assign, nonatomic) BOOL shouldDisableiCloud;
/**
* use memory cache [defaults to YES]
*/
@property (assign, nonatomic) BOOL shouldCacheImagesInMemory;
/** /**
* The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
*/ */
...@@ -254,7 +244,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot ...@@ -254,7 +244,7 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
* Get the cache path for a certain key (needs the cache path root folder) * Get the cache path for a certain key (needs the cache path root folder)
* *
* @param key the key (can be obtained from url using cacheKeyForURL) * @param key the key (can be obtained from url using cacheKeyForURL)
* @param path the cache path root folder * @param path the cach path root folder
* *
* @return the cache path * @return the cache path
*/ */
......
...@@ -116,12 +116,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -116,12 +116,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
// Set decompression to YES // Set decompression to YES
_shouldDecompressImages = YES; _shouldDecompressImages = YES;
// memory cache enabled
_shouldCacheImagesInMemory = YES;
// Disable iCloud
_shouldDisableiCloud = YES;
dispatch_sync(_ioQueue, ^{ dispatch_sync(_ioQueue, ^{
_fileManager = [NSFileManager new]; _fileManager = [NSFileManager new];
}); });
...@@ -181,9 +175,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -181,9 +175,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
} }
unsigned char r[CC_MD5_DIGEST_LENGTH]; unsigned char r[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, (CC_LONG)strlen(str), r); CC_MD5(str, (CC_LONG)strlen(str), r);
NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%@", NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]];
r[11], r[12], r[13], r[14], r[15], [[key pathExtension] isEqualToString:@""] ? @"" : [NSString stringWithFormat:@".%@", [key pathExtension]]];
return filename; return filename;
} }
...@@ -200,11 +193,9 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -200,11 +193,9 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
if (!image || !key) { if (!image || !key) {
return; return;
} }
// if memory cache is enabled
if (self.shouldCacheImagesInMemory) { NSUInteger cost = SDCacheCostForImage(image);
NSUInteger cost = SDCacheCostForImage(image); [self.memCache setObject:image forKey:key cost:cost];
[self.memCache setObject:image forKey:key cost:cost];
}
if (toDisk) { if (toDisk) {
dispatch_async(self.ioQueue, ^{ dispatch_async(self.ioQueue, ^{
...@@ -246,17 +237,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -246,17 +237,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
[_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
} }
// get cache Path for image key [_fileManager createFileAtPath:[self defaultCachePathForKey:key] contents:data attributes:nil];
NSString *cachePathForKey = [self defaultCachePathForKey:key];
// transform to NSUrl
NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey];
[_fileManager createFileAtPath:cachePathForKey contents:data attributes:nil];
// disable iCloud backup
if (self.shouldDisableiCloud) {
[fileURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
} }
}); });
} }
...@@ -276,12 +257,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -276,12 +257,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
// this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance // this is an exception to access the filemanager on another queue than ioQueue, but we are using the shared instance
// from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely. // from apple docs on NSFileManager: The methods of the shared NSFileManager object can be called from multiple threads safely.
exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]]; exists = [[NSFileManager defaultManager] fileExistsAtPath:[self defaultCachePathForKey:key]];
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
// checking the key with and without the extension
if (!exists) {
exists = [[NSFileManager defaultManager] fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
}
return exists; return exists;
} }
...@@ -289,13 +264,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -289,13 +264,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
- (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock { - (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock {
dispatch_async(_ioQueue, ^{ dispatch_async(_ioQueue, ^{
BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
// checking the key with and without the extension
if (!exists) {
exists = [_fileManager fileExistsAtPath:[[self defaultCachePathForKey:key] stringByDeletingPathExtension]];
}
if (completionBlock) { if (completionBlock) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
completionBlock(exists); completionBlock(exists);
...@@ -309,7 +277,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -309,7 +277,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
} }
- (UIImage *)imageFromDiskCacheForKey:(NSString *)key { - (UIImage *)imageFromDiskCacheForKey:(NSString *)key {
// First check the in-memory cache... // First check the in-memory cache...
UIImage *image = [self imageFromMemoryCacheForKey:key]; UIImage *image = [self imageFromMemoryCacheForKey:key];
if (image) { if (image) {
...@@ -318,7 +285,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -318,7 +285,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
// Second check the disk cache... // Second check the disk cache...
UIImage *diskImage = [self diskImageForKey:key]; UIImage *diskImage = [self diskImageForKey:key];
if (diskImage && self.shouldCacheImagesInMemory) { if (diskImage) {
NSUInteger cost = SDCacheCostForImage(diskImage); NSUInteger cost = SDCacheCostForImage(diskImage);
[self.memCache setObject:diskImage forKey:key cost:cost]; [self.memCache setObject:diskImage forKey:key cost:cost];
} }
...@@ -333,13 +300,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -333,13 +300,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
return data; return data;
} }
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
// checking the key with and without the extension
data = [NSData dataWithContentsOfFile:[defaultPath stringByDeletingPathExtension]];
if (data) {
return data;
}
NSArray *customPaths = [self.customPaths copy]; NSArray *customPaths = [self.customPaths copy];
for (NSString *path in customPaths) { for (NSString *path in customPaths) {
NSString *filePath = [self cachePathForKey:key inPath:path]; NSString *filePath = [self cachePathForKey:key inPath:path];
...@@ -347,13 +307,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -347,13 +307,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
if (imageData) { if (imageData) {
return imageData; return imageData;
} }
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
// checking the key with and without the extension
imageData = [NSData dataWithContentsOfFile:[filePath stringByDeletingPathExtension]];
if (imageData) {
return imageData;
}
} }
return nil; return nil;
...@@ -403,7 +356,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -403,7 +356,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
@autoreleasepool { @autoreleasepool {
UIImage *diskImage = [self diskImageForKey:key]; UIImage *diskImage = [self diskImageForKey:key];
if (diskImage && self.shouldCacheImagesInMemory) { if (diskImage) {
NSUInteger cost = SDCacheCostForImage(diskImage); NSUInteger cost = SDCacheCostForImage(diskImage);
[self.memCache setObject:diskImage forKey:key cost:cost]; [self.memCache setObject:diskImage forKey:key cost:cost];
} }
...@@ -434,11 +387,9 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { ...@@ -434,11 +387,9 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
if (key == nil) { if (key == nil) {
return; return;
} }
if (self.shouldCacheImagesInMemory) { [self.memCache removeObjectForKey:key];
[self.memCache removeObjectForKey:key];
}
if (fromDisk) { if (fromDisk) {
dispatch_async(self.ioQueue, ^{ dispatch_async(self.ioQueue, ^{
[_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil]; [_fileManager removeItemAtPath:[self defaultCachePathForKey:key] error:nil];
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#endif #endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
#error SDWebImage doesn't support Deployment Target version < 5.0 #error SDWebImage doesn't support Deployement Target version < 5.0
#endif #endif
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
......
...@@ -28,7 +28,7 @@ inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { ...@@ -28,7 +28,7 @@ inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
} }
else { else {
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
CGFloat scale = [UIScreen mainScreen].scale; CGFloat scale = 1.0;
if (key.length >= 8) { if (key.length >= 8) {
NSRange range = [key rangeOfString:@"@2x."]; NSRange range = [key rangeOfString:@"@2x."];
if (range.location != NSNotFound) { if (range.location != NSNotFound) {
......
...@@ -13,57 +13,60 @@ ...@@ -13,57 +13,60 @@
@implementation UIImage (ForceDecode) @implementation UIImage (ForceDecode)
+ (UIImage *)decodedImageWithImage:(UIImage *)image { + (UIImage *)decodedImageWithImage:(UIImage *)image {
// while downloading huge amount of images if (image.images) {
// autorelease the bitmap context // Do not decode animated images
// and all vars to help system to free memory return image;
// when there are memory warning.
// on iOS7, do not forget to call
// [[SDImageCache sharedImageCache] clearMemory];
@autoreleasepool{
// do not decode animated images
if (image.images) { return image; }
CGImageRef imageRef = image.CGImage;
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef);
BOOL anyAlpha = (alpha == kCGImageAlphaFirst ||
alpha == kCGImageAlphaLast ||
alpha == kCGImageAlphaPremultipliedFirst ||
alpha == kCGImageAlphaPremultipliedLast);
if (anyAlpha) { return image; }
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
// current
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelCMYK || imageColorSpaceModel == kCGColorSpaceModelIndexed);
if (unsupportedColorSpace)
colorspaceRef = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width,
height,
CGImageGetBitsPerComponent(imageRef),
0,
colorspaceRef,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
// Draw the image into the context and retrieve the new image, which will now have an alpha layer
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context);
UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation];
if (unsupportedColorSpace)
CGColorSpaceRelease(colorspaceRef);
CGContextRelease(context);
CGImageRelease(imageRefWithAlpha);
return imageWithAlpha;
} }
CGImageRef imageRef = image.CGImage;
CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
int infoMask = (bitmapInfo & kCGBitmapAlphaInfoMask);
BOOL anyNonAlpha = (infoMask == kCGImageAlphaNone ||
infoMask == kCGImageAlphaNoneSkipFirst ||
infoMask == kCGImageAlphaNoneSkipLast);
// CGBitmapContextCreate doesn't support kCGImageAlphaNone with RGB.
// https://developer.apple.com/library/mac/#qa/qa1037/_index.html
if (infoMask == kCGImageAlphaNone && CGColorSpaceGetNumberOfComponents(colorSpace) > 1) {
// Unset the old alpha info.
bitmapInfo &= ~kCGBitmapAlphaInfoMask;
// Set noneSkipFirst.
bitmapInfo |= kCGImageAlphaNoneSkipFirst;
}
// Some PNGs tell us they have alpha but only 3 components. Odd.
else if (!anyNonAlpha && CGColorSpaceGetNumberOfComponents(colorSpace) == 3) {
// Unset the old alpha info.
bitmapInfo &= ~kCGBitmapAlphaInfoMask;
bitmapInfo |= kCGImageAlphaPremultipliedFirst;
}
// It calculates the bytes-per-row based on the bitsPerComponent and width arguments.
CGContextRef context = CGBitmapContextCreate(NULL,
imageSize.width,
imageSize.height,
CGImageGetBitsPerComponent(imageRef),
0,
colorSpace,
bitmapInfo);
CGColorSpaceRelease(colorSpace);
// If failed, return undecompressed image
if (!context) return image;
CGContextDrawImage(context, imageRect, imageRef);
CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation];
CGImageRelease(decompressedImageRef);
return decompressedImage;
} }
@end @end
...@@ -40,7 +40,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { ...@@ -40,7 +40,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
SDWebImageDownloaderHandleCookies = 1 << 5, SDWebImageDownloaderHandleCookies = 1 << 5,
/** /**
* Enable to allow untrusted SSL certificates. * Enable to allow untrusted SSL ceriticates.
* Useful for testing purposes. Use with caution in production. * Useful for testing purposes. Use with caution in production.
*/ */
SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
...@@ -78,7 +78,7 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi ...@@ -78,7 +78,7 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
@interface SDWebImageDownloader : NSObject @interface SDWebImageDownloader : NSObject
/** /**
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. * Decompressing images that are downloaded and cached can improve peformance but can consume lot of memory.
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
*/ */
@property (assign, nonatomic) BOOL shouldDecompressImages; @property (assign, nonatomic) BOOL shouldDecompressImages;
...@@ -109,11 +109,6 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi ...@@ -109,11 +109,6 @@ typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDi
*/ */
+ (SDWebImageDownloader *)sharedDownloader; + (SDWebImageDownloader *)sharedDownloader;
/**
* Set the default URL credential to be set for request operations.
*/
@property (strong, nonatomic) NSURLCredential *urlCredential;
/** /**
* Set username * Set username
*/ */
......
...@@ -116,7 +116,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; ...@@ -116,7 +116,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
__block SDWebImageDownloaderOperation *operation; __block SDWebImageDownloaderOperation *operation;
__weak __typeof(self)wself = self; __weak __typeof(self)wself = self;
[self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
NSTimeInterval timeoutInterval = wself.downloadTimeout; NSTimeInterval timeoutInterval = wself.downloadTimeout;
if (timeoutInterval == 0.0) { if (timeoutInterval == 0.0) {
timeoutInterval = 15.0; timeoutInterval = 15.0;
...@@ -142,10 +142,8 @@ static NSString *const kCompletedCallbackKey = @"completed"; ...@@ -142,10 +142,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
callbacksForURL = [sself.URLCallbacks[url] copy]; callbacksForURL = [sself.URLCallbacks[url] copy];
}); });
for (NSDictionary *callbacks in callbacksForURL) { for (NSDictionary *callbacks in callbacksForURL) {
dispatch_async(dispatch_get_main_queue(), ^{ SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; if (callback) callback(receivedSize, expectedSize);
if (callback) callback(receivedSize, expectedSize);
});
} }
} }
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
...@@ -172,9 +170,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; ...@@ -172,9 +170,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
}]; }];
operation.shouldDecompressImages = wself.shouldDecompressImages; operation.shouldDecompressImages = wself.shouldDecompressImages;
if (wself.urlCredential) { if (wself.username && wself.password) {
operation.credential = wself.urlCredential;
} else if (wself.username && wself.password) {
operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
} }
...@@ -195,7 +191,7 @@ static NSString *const kCompletedCallbackKey = @"completed"; ...@@ -195,7 +191,7 @@ static NSString *const kCompletedCallbackKey = @"completed";
return operation; return operation;
} }
- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback { - (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock andCompletedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
// The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
if (url == nil) { if (url == nil) {
if (completedBlock != nil) { if (completedBlock != nil) {
......
...@@ -41,7 +41,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { ...@@ -41,7 +41,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
* This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
* If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
* *
* Use this flag only if you can't make your URLs static with embedded cache busting parameter. * Use this flag only if you can't make your URLs static with embeded cache busting parameter.
*/ */
SDWebImageRefreshCached = 1 << 4, SDWebImageRefreshCached = 1 << 4,
...@@ -58,7 +58,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { ...@@ -58,7 +58,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
SDWebImageHandleCookies = 1 << 6, SDWebImageHandleCookies = 1 << 6,
/** /**
* Enable to allow untrusted SSL certificates. * Enable to allow untrusted SSL ceriticates.
* Useful for testing purposes. Use with caution in production. * Useful for testing purposes. Use with caution in production.
*/ */
SDWebImageAllowInvalidSSLCertificates = 1 << 7, SDWebImageAllowInvalidSSLCertificates = 1 << 7,
...@@ -195,11 +195,11 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; ...@@ -195,11 +195,11 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
* This block has no return value and takes the requested UIImage as first parameter. * This block has no return value and takes the requested UIImage as first parameter.
* In case of error the image parameter is nil and the second parameter may contain an NSError. * In case of error the image parameter is nil and the second parameter may contain an NSError.
* *
* The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache * The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache
* or from the memory cache or from the network. * or from the memory cache or from the network.
* *
* The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
* downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the * downloading. This block is thus called repetidly with a partial image. When image is fully downloaded, the
* block is called a last time with the full image and the last parameter set to YES. * block is called a last time with the full image and the last parameter set to YES.
* *
* @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
...@@ -220,7 +220,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; ...@@ -220,7 +220,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
- (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
/** /**
* Cancel all current operations * Cancel all current opreations
*/ */
- (void)cancelAll; - (void)cancelAll;
......
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
isFailedUrl = [self.failedURLs containsObject:url]; isFailedUrl = [self.failedURLs containsObject:url];
} }
if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) {
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]; NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
completedBlock(nil, error, SDImageCacheTypeNone, YES, url); completedBlock(nil, error, SDImageCacheTypeNone, YES, url);
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) { if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:@selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url])) {
if (image && options & SDWebImageRefreshCached) { if (image && options & SDWebImageRefreshCached) {
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
// If image was found in the cache but SDWebImageRefreshCached is provided, notify about the cached image // If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server. // AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
completedBlock(image, nil, cacheType, YES, url); completedBlock(image, nil, cacheType, YES, url);
}); });
...@@ -180,26 +180,21 @@ ...@@ -180,26 +180,21 @@
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
} }
id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) { id <SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) {
__strong __typeof(weakOperation) strongOperation = weakOperation; if (weakOperation.isCancelled) {
if (!strongOperation || strongOperation.isCancelled) {
// Do nothing if the operation was cancelled // Do nothing if the operation was cancelled
// See #699 for more details // See #699 for more details
// if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data // if we would call the completedBlock, there could be a race condition between this block and another completedBlock for the same object, so if this one is called second, we will overwrite the new data
} }
else if (error) { else if (error) {
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
if (strongOperation && !strongOperation.isCancelled) { if (!weakOperation.isCancelled) {
completedBlock(nil, error, SDImageCacheTypeNone, finished, url); completedBlock(nil, error, SDImageCacheTypeNone, finished, url);
} }
}); });
if ( error.code != NSURLErrorNotConnectedToInternet BOOL shouldBeFailedURLAlliOSVersion = (error.code != NSURLErrorNotConnectedToInternet && error.code != NSURLErrorCancelled && error.code != NSURLErrorTimedOut);
&& error.code != NSURLErrorCancelled BOOL shouldBeFailedURLiOS7 = (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1 && error.code != NSURLErrorInternationalRoamingOff && error.code != NSURLErrorCallIsActive && error.code != NSURLErrorDataNotAllowed);
&& error.code != NSURLErrorTimedOut if (shouldBeFailedURLAlliOSVersion || shouldBeFailedURLiOS7) {
&& error.code != NSURLErrorInternationalRoamingOff
&& error.code != NSURLErrorDataNotAllowed
&& error.code != NSURLErrorCannotFindHost
&& error.code != NSURLErrorCannotConnectToHost) {
@synchronized (self.failedURLs) { @synchronized (self.failedURLs) {
[self.failedURLs addObject:url]; [self.failedURLs addObject:url];
} }
...@@ -227,7 +222,7 @@ ...@@ -227,7 +222,7 @@
} }
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
if (strongOperation && !strongOperation.isCancelled) { if (!weakOperation.isCancelled) {
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url); completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished, url);
} }
}); });
...@@ -239,7 +234,7 @@ ...@@ -239,7 +234,7 @@
} }
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
if (strongOperation && !strongOperation.isCancelled) { if (!weakOperation.isCancelled) {
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url); completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished, url);
} }
}); });
...@@ -248,9 +243,7 @@ ...@@ -248,9 +243,7 @@
if (finished) { if (finished) {
@synchronized (self.runningOperations) { @synchronized (self.runningOperations) {
if (strongOperation) { [self.runningOperations removeObject:operation];
[self.runningOperations removeObject:strongOperation];
}
} }
} }
}]; }];
...@@ -258,17 +251,13 @@ ...@@ -258,17 +251,13 @@
[subOperation cancel]; [subOperation cancel];
@synchronized (self.runningOperations) { @synchronized (self.runningOperations) {
__strong __typeof(weakOperation) strongOperation = weakOperation; [self.runningOperations removeObject:weakOperation];
if (strongOperation) {
[self.runningOperations removeObject:strongOperation];
}
} }
}; };
} }
else if (image) { else if (image) {
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
__strong __typeof(weakOperation) strongOperation = weakOperation; if (!weakOperation.isCancelled) {
if (strongOperation && !strongOperation.isCancelled) {
completedBlock(image, nil, cacheType, YES, url); completedBlock(image, nil, cacheType, YES, url);
} }
}); });
...@@ -279,8 +268,7 @@ ...@@ -279,8 +268,7 @@
else { else {
// Image not in cache and download disallowed by delegate // Image not in cache and download disallowed by delegate
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
__strong __typeof(weakOperation) strongOperation = weakOperation; if (!weakOperation.isCancelled) {
if (strongOperation && !weakOperation.isCancelled) {
completedBlock(nil, nil, SDImageCacheTypeNone, YES, url); completedBlock(nil, nil, SDImageCacheTypeNone, YES, url);
} }
}); });
...@@ -309,11 +297,7 @@ ...@@ -309,11 +297,7 @@
} }
- (BOOL)isRunning { - (BOOL)isRunning {
BOOL isRunning = NO; return self.runningOperations.count > 0;
@synchronized(self.runningOperations) {
isRunning = (self.runningOperations.count > 0);
}
return isRunning;
} }
@end @end
......
...@@ -70,11 +70,6 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, ...@@ -70,11 +70,6 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
*/ */
+ (SDWebImagePrefetcher *)sharedImagePrefetcher; + (SDWebImagePrefetcher *)sharedImagePrefetcher;
/**
* Allows you to instantiate a prefetcher with any arbitrary image manager.
*/
- (id)initWithImageManager:(SDWebImageManager *)manager;
/** /**
* Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
* currently one image is downloaded at a time, * currently one image is downloaded at a time,
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#import "SDWebImagePrefetcher.h" #import "SDWebImagePrefetcher.h"
#if (!defined(DEBUG) && !defined (SD_VERBOSE)) || defined(SD_LOG_NONE)
#define NSLog(...)
#endif
@interface SDWebImagePrefetcher () @interface SDWebImagePrefetcher ()
@property (strong, nonatomic) SDWebImageManager *manager; @property (strong, nonatomic) SDWebImageManager *manager;
...@@ -33,12 +37,8 @@ ...@@ -33,12 +37,8 @@
} }
- (id)init { - (id)init {
return [self initWithImageManager:[SDWebImageManager new]];
}
- (id)initWithImageManager:(SDWebImageManager *)manager {
if ((self = [super init])) { if ((self = [super init])) {
_manager = manager; _manager = [SDWebImageManager new];
_options = SDWebImageLowPriority; _options = SDWebImageLowPriority;
_prefetcherQueue = dispatch_get_main_queue(); _prefetcherQueue = dispatch_get_main_queue();
self.maxConcurrentDownloads = 3; self.maxConcurrentDownloads = 3;
...@@ -65,11 +65,14 @@ ...@@ -65,11 +65,14 @@
if (self.progressBlock) { if (self.progressBlock) {
self.progressBlock(self.finishedCount,[self.prefetchURLs count]); self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
} }
NSLog(@"Prefetched %@ out of %@", @(self.finishedCount), @(self.prefetchURLs.count));
} }
else { else {
if (self.progressBlock) { if (self.progressBlock) {
self.progressBlock(self.finishedCount,[self.prefetchURLs count]); self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
} }
NSLog(@"Prefetched %@ out of %@ (Failed)", @(self.finishedCount), @(self.prefetchURLs.count));
// Add last failed // Add last failed
self.skippedCount++; self.skippedCount++;
} }
...@@ -78,13 +81,14 @@ ...@@ -78,13 +81,14 @@
didPrefetchURL:self.prefetchURLs[index] didPrefetchURL:self.prefetchURLs[index]
finishedCount:self.finishedCount finishedCount:self.finishedCount
totalCount:self.prefetchURLs.count totalCount:self.prefetchURLs.count
]; ];
} }
if (self.prefetchURLs.count > self.requestedCount) { if (self.prefetchURLs.count > self.requestedCount) {
dispatch_async(self.prefetcherQueue, ^{ dispatch_async(self.prefetcherQueue, ^{
[self startPrefetchingAtIndex:self.requestedCount]; [self startPrefetchingAtIndex:self.requestedCount];
}); });
} else if (self.finishedCount == self.requestedCount) { }
else if (self.finishedCount == self.requestedCount) {
[self reportStatus]; [self reportStatus];
if (self.completionBlock) { if (self.completionBlock) {
self.completionBlock(self.finishedCount, self.skippedCount); self.completionBlock(self.finishedCount, self.skippedCount);
...@@ -97,11 +101,12 @@ ...@@ -97,11 +101,12 @@
- (void)reportStatus { - (void)reportStatus {
NSUInteger total = [self.prefetchURLs count]; NSUInteger total = [self.prefetchURLs count];
NSLog(@"Finished prefetching (%@ successful, %@ skipped, timeElasped %.2f)", @(total - self.skippedCount), @(self.skippedCount), CFAbsoluteTimeGetCurrent() - self.startedTime);
if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
[self.delegate imagePrefetcher:self [self.delegate imagePrefetcher:self
didFinishWithTotalCount:(total - self.skippedCount) didFinishWithTotalCount:(total - self.skippedCount)
skippedCount:self.skippedCount skippedCount:self.skippedCount
]; ];
} }
} }
...@@ -116,11 +121,11 @@ ...@@ -116,11 +121,11 @@
self.completionBlock = completionBlock; self.completionBlock = completionBlock;
self.progressBlock = progressBlock; self.progressBlock = progressBlock;
if (urls.count == 0) { if(urls.count == 0){
if (completionBlock) { if(completionBlock){
completionBlock(0,0); completionBlock(0,0);
} }
} else { }else{
// Starts prefetching from the very first image on the list with the max allowed concurrency // Starts prefetching from the very first image on the list with the max allowed concurrency
NSUInteger listCount = self.prefetchURLs.count; NSUInteger listCount = self.prefetchURLs.count;
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -184,7 +184,7 @@ ...@@ -184,7 +184,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
......
...@@ -57,8 +57,8 @@ static char imageURLStorageKey; ...@@ -57,8 +57,8 @@ static char imageURLStorageKey;
[self.imageURLStorage removeObjectForKey:@(state)]; [self.imageURLStorage removeObjectForKey:@(state)];
dispatch_main_async_safe(^{ dispatch_main_async_safe(^{
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
if (completedBlock) { if (completedBlock) {
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
completedBlock(nil, error, SDImageCacheTypeNone, url); completedBlock(nil, error, SDImageCacheTypeNone, url);
} }
}); });
...@@ -74,12 +74,7 @@ static char imageURLStorageKey; ...@@ -74,12 +74,7 @@ static char imageURLStorageKey;
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
__strong UIButton *sself = wself; __strong UIButton *sself = wself;
if (!sself) return; if (!sself) return;
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) if (image) {
{
completedBlock(image, error, cacheType, url);
return;
}
else if (image) {
[sself setImage:image forState:state]; [sself setImage:image forState:state];
} }
if (completedBlock && finished) { if (completedBlock && finished) {
...@@ -111,7 +106,7 @@ static char imageURLStorageKey; ...@@ -111,7 +106,7 @@ static char imageURLStorageKey;
} }
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
[self sd_cancelBackgroundImageLoadForState:state]; [self sd_cancelImageLoadForState:state];
[self setBackgroundImage:placeholder forState:state]; [self setBackgroundImage:placeholder forState:state];
...@@ -122,12 +117,7 @@ static char imageURLStorageKey; ...@@ -122,12 +117,7 @@ static char imageURLStorageKey;
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
__strong UIButton *sself = wself; __strong UIButton *sself = wself;
if (!sself) return; if (!sself) return;
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) if (image) {
{
completedBlock(image, error, cacheType, url);
return;
}
else if (image) {
[sself setBackgroundImage:image forState:state]; [sself setBackgroundImage:image forState:state];
} }
if (completedBlock && finished) { if (completedBlock && finished) {
......
...@@ -141,17 +141,17 @@ ...@@ -141,17 +141,17 @@
NSMutableArray *scaledImages = [NSMutableArray array]; NSMutableArray *scaledImages = [NSMutableArray array];
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
for (UIImage *image in self.images) { for (UIImage *image in self.images) {
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
[scaledImages addObject:newImage]; [scaledImages addObject:newImage];
UIGraphicsEndImageContext();
} }
UIGraphicsEndImageContext();
return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
} }
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
......
...@@ -39,12 +39,7 @@ ...@@ -39,12 +39,7 @@
dispatch_main_sync_safe (^ dispatch_main_sync_safe (^
{ {
if (!wself) return; if (!wself) return;
if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) if (image) {
{
completedBlock(image, error, cacheType, url);
return;
}
else if (image) {
wself.highlightedImage = image; wself.highlightedImage = image;
[wself setNeedsLayout]; [wself setNeedsLayout];
} }
......
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -107,7 +107,7 @@ ...@@ -107,7 +107,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
...@@ -140,13 +140,13 @@ ...@@ -140,13 +140,13 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
/** /**
* Set the imageView `image` with an `url` and optionally a placeholder image. * Set the imageView `image` with an `url` and a optionaly placeholder image.
* *
* The download is asynchronous and cached. * The download is asynchronous and cached.
* *
...@@ -157,10 +157,10 @@ ...@@ -157,10 +157,10 @@
* @param completedBlock A block called when operation has been completed. This block has no return value * @param completedBlock A block called when operation has been completed. This block has no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter * and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrieved from the local cache or from the network. * indicating if the image was retrived from the local cache or from the network.
* The fourth parameter is the original image url. * The fourth parameter is the original image url.
*/ */
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
/** /**
* Download an array of images and starts them in an animation loop * Download an array of images and starts them in an animation loop
...@@ -176,18 +176,6 @@ ...@@ -176,18 +176,6 @@
- (void)sd_cancelCurrentAnimationImagesLoad; - (void)sd_cancelCurrentAnimationImagesLoad;
/**
* Show activity UIActivityIndicatorView
*/
- (void)setShowActivityIndicatorView:(BOOL)show;
/**
* set desired UIActivityIndicatorViewStyle
*
* @param style The style of the UIActivityIndicatorView
*/
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
@end @end
......
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
#import "UIView+WebCacheOperation.h" #import "UIView+WebCacheOperation.h"
static char imageURLKey; static char imageURLKey;
static char TAG_ACTIVITY_INDICATOR;
static char TAG_ACTIVITY_STYLE;
static char TAG_ACTIVITY_SHOW;
@implementation UIImageView (WebCache) @implementation UIImageView (WebCache)
...@@ -52,15 +49,8 @@ static char TAG_ACTIVITY_SHOW; ...@@ -52,15 +49,8 @@ static char TAG_ACTIVITY_SHOW;
} }
if (url) { if (url) {
// check if activityView is enabled or not
if ([self showActivityIndicatorView]) {
[self addActivityIndicator];
}
__weak __typeof(self)wself = self; __weak __typeof(self)wself = self;
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
[wself removeActivityIndicator];
if (!wself) return; if (!wself) return;
dispatch_main_sync_safe(^{ dispatch_main_sync_safe(^{
if (!wself) return; if (!wself) return;
...@@ -86,16 +76,15 @@ static char TAG_ACTIVITY_SHOW; ...@@ -86,16 +76,15 @@ static char TAG_ACTIVITY_SHOW;
[self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
} else { } else {
dispatch_main_async_safe(^{ dispatch_main_async_safe(^{
[self removeActivityIndicator]; NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
if (completedBlock) { if (completedBlock) {
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
completedBlock(nil, error, SDImageCacheTypeNone, url); completedBlock(nil, error, SDImageCacheTypeNone, url);
} }
}); });
} }
} }
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key]; UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
...@@ -145,70 +134,6 @@ static char TAG_ACTIVITY_SHOW; ...@@ -145,70 +134,6 @@ static char TAG_ACTIVITY_SHOW;
[self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
} }
#pragma mark -
- (UIActivityIndicatorView *)activityIndicator {
return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR);
}
- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator {
objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
}
- (void)setShowActivityIndicatorView:(BOOL)show{
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN);
}
- (BOOL)showActivityIndicatorView{
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
}
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{
objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN);
}
- (int)getIndicatorStyle{
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue];
}
- (void)addActivityIndicator {
if (!self.activityIndicator) {
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]];
self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
dispatch_main_async_safe(^{
[self addSubview:self.activityIndicator];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0.0]];
});
}
dispatch_main_async_safe(^{
[self.activityIndicator startAnimating];
});
}
- (void)removeActivityIndicator {
if (self.activityIndicator) {
[self.activityIndicator removeFromSuperview];
self.activityIndicator = nil;
}
}
@end @end
......
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/AFNetworking" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/AFNetworking" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/UMengAnalytics"
OTHER_LDFLAGS = -framework "CoreGraphics" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" OTHER_LDFLAGS = -framework "CoreGraphics" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration"
PODS_ROOT = ${SRCROOT} PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES SKIP_INSTALL = YES
\ No newline at end of file
...@@ -119,4 +119,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -119,4 +119,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
## UMengAnalytics
Copyright 2011 - 2015 UMeng.com. All rights reserved.
Generated by CocoaPods - http://cocoapods.org Generated by CocoaPods - http://cocoapods.org
...@@ -155,6 +155,15 @@ THE SOFTWARE. ...@@ -155,6 +155,15 @@ THE SOFTWARE.
<key>Type</key> <key>Type</key>
<string>PSGroupSpecifier</string> <string>PSGroupSpecifier</string>
</dict> </dict>
<dict>
<key>FooterText</key>
<string>Copyright 2011 - 2015 UMeng.com. All rights reserved.
</string>
<key>Title</key>
<string>UMengAnalytics</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict> <dict>
<key>FooterText</key> <key>FooterText</key>
<string>Generated by CocoaPods - http://cocoapods.org</string> <string>Generated by CocoaPods - http://cocoapods.org</string>
......
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/UMengAnalytics"
LIBRARY_SEARCH_PATHS = $(PODS_ROOT)/JPushSDK/lib LIBRARY_SEARCH_PATHS = $(PODS_ROOT)/JPushSDK/lib "$(PODS_ROOT)/UMengAnalytics/**"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking" -isystem "${PODS_ROOT}/Headers/Public/JPushSDK" -isystem "${PODS_ROOT}/Headers/Public/MBProgressHUD" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/RATreeView" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking" -isystem "${PODS_ROOT}/Headers/Public/JPushSDK" -isystem "${PODS_ROOT}/Headers/Public/MBProgressHUD" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/RATreeView" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/UMengAnalytics"
OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"MBProgressHUD" -l"MJRefresh" -l"RATreeView" -l"SDWebImage" -l"z" -framework "CFNetwork" -framework "CoreFoundation" -framework "CoreGraphics" -framework "CoreTelephony" -framework "Foundation" -framework "ImageIO" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" -framework "UIKit" OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"MBProgressHUD" -l"MJRefresh" -l"MobClickLibrary" -l"RATreeView" -l"SDWebImage" -l"z" -framework "CFNetwork" -framework "CoreFoundation" -framework "CoreGraphics" -framework "CoreTelephony" -framework "Foundation" -framework "ImageIO" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" -framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods PODS_ROOT = ${SRCROOT}/Pods
\ No newline at end of file
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" HEADER_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/UMengAnalytics"
LIBRARY_SEARCH_PATHS = $(PODS_ROOT)/JPushSDK/lib LIBRARY_SEARCH_PATHS = $(PODS_ROOT)/JPushSDK/lib "$(PODS_ROOT)/UMengAnalytics/**"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking" -isystem "${PODS_ROOT}/Headers/Public/JPushSDK" -isystem "${PODS_ROOT}/Headers/Public/MBProgressHUD" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/RATreeView" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking" -isystem "${PODS_ROOT}/Headers/Public/JPushSDK" -isystem "${PODS_ROOT}/Headers/Public/MBProgressHUD" -isystem "${PODS_ROOT}/Headers/Public/MJRefresh" -isystem "${PODS_ROOT}/Headers/Public/RATreeView" -isystem "${PODS_ROOT}/Headers/Public/SDWebImage" -isystem "${PODS_ROOT}/Headers/Public/UMengAnalytics"
OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"MBProgressHUD" -l"MJRefresh" -l"RATreeView" -l"SDWebImage" -l"z" -framework "CFNetwork" -framework "CoreFoundation" -framework "CoreGraphics" -framework "CoreTelephony" -framework "Foundation" -framework "ImageIO" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" -framework "UIKit" OTHER_LDFLAGS = $(inherited) -ObjC -l"AFNetworking" -l"MBProgressHUD" -l"MJRefresh" -l"MobClickLibrary" -l"RATreeView" -l"SDWebImage" -l"z" -framework "CFNetwork" -framework "CoreFoundation" -framework "CoreGraphics" -framework "CoreTelephony" -framework "Foundation" -framework "ImageIO" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration" -framework "UIKit"
PODS_ROOT = ${SRCROOT}/Pods PODS_ROOT = ${SRCROOT}/Pods
\ No newline at end of file
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SDWebImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/SDWebImage" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking" "${PODS_ROOT}/Headers/Public/JPushSDK" "${PODS_ROOT}/Headers/Public/MBProgressHUD" "${PODS_ROOT}/Headers/Public/MJRefresh" "${PODS_ROOT}/Headers/Public/RATreeView" "${PODS_ROOT}/Headers/Public/SDWebImage" "${PODS_ROOT}/Headers/Public/UMengAnalytics"
OTHER_LDFLAGS = -framework "ImageIO" OTHER_LDFLAGS = -framework "ImageIO"
PODS_ROOT = ${SRCROOT} PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES SKIP_INSTALL = YES
\ No newline at end of file
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
2381E9EBA834CB171E43657A /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 083F3F95EB690FA24FEC0C8E /* libPods.a */; }; 2381E9EBA834CB171E43657A /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 083F3F95EB690FA24FEC0C8E /* libPods.a */; };
35C7F45A1C8D591900EE7EDD /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 35C7F4591C8D591900EE7EDD /* libz.tbd */; };
35F68BCA1C30FBA800994F53 /* PushConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 35F68BC91C30FBA800994F53 /* PushConfig.plist */; }; 35F68BCA1C30FBA800994F53 /* PushConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 35F68BC91C30FBA800994F53 /* PushConfig.plist */; };
35F68BCC1C30FF8500994F53 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35F68BCB1C30FF8500994F53 /* CoreGraphics.framework */; }; 35F68BCC1C30FF8500994F53 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35F68BCB1C30FF8500994F53 /* CoreGraphics.framework */; };
35F68BCE1C30FF8F00994F53 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35F68BCD1C30FF8F00994F53 /* SystemConfiguration.framework */; }; 35F68BCE1C30FF8F00994F53 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35F68BCD1C30FF8F00994F53 /* SystemConfiguration.framework */; };
...@@ -224,6 +225,7 @@ ...@@ -224,6 +225,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
083F3F95EB690FA24FEC0C8E /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 083F3F95EB690FA24FEC0C8E /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
13B0DDED3E0E584D79B395CF /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; }; 13B0DDED3E0E584D79B395CF /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = "<group>"; };
35C7F4591C8D591900EE7EDD /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
35F68BC91C30FBA800994F53 /* PushConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PushConfig.plist; sourceTree = "<group>"; }; 35F68BC91C30FBA800994F53 /* PushConfig.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PushConfig.plist; sourceTree = "<group>"; };
35F68BCB1C30FF8500994F53 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 35F68BCB1C30FF8500994F53 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
35F68BCD1C30FF8F00994F53 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 35F68BCD1C30FF8F00994F53 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
...@@ -610,6 +612,7 @@ ...@@ -610,6 +612,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
35C7F45A1C8D591900EE7EDD /* libz.tbd in Frameworks */,
35F68BDE1C30FFF300994F53 /* Security.framework in Frameworks */, 35F68BDE1C30FFF300994F53 /* Security.framework in Frameworks */,
35F68BDC1C30FFEA00994F53 /* OpenGLES.framework in Frameworks */, 35F68BDC1C30FFEA00994F53 /* OpenGLES.framework in Frameworks */,
35F68BDA1C30FFDE00994F53 /* QuartzCore.framework in Frameworks */, 35F68BDA1C30FFDE00994F53 /* QuartzCore.framework in Frameworks */,
...@@ -2334,6 +2337,7 @@ ...@@ -2334,6 +2337,7 @@
DA794C35494A6C844D6EE3C9 /* Frameworks */ = { DA794C35494A6C844D6EE3C9 /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
35C7F4591C8D591900EE7EDD /* libz.tbd */,
35F68BDD1C30FFF300994F53 /* Security.framework */, 35F68BDD1C30FFF300994F53 /* Security.framework */,
35F68BDB1C30FFEA00994F53 /* OpenGLES.framework */, 35F68BDB1C30FFEA00994F53 /* OpenGLES.framework */,
35F68BD91C30FFDE00994F53 /* QuartzCore.framework */, 35F68BD91C30FFDE00994F53 /* QuartzCore.framework */,
...@@ -2419,6 +2423,7 @@ ...@@ -2419,6 +2423,7 @@
TargetAttributes = { TargetAttributes = {
84970DE91BD8DD8A00C1728A = { 84970DE91BD8DD8A00C1728A = {
CreatedOnToolsVersion = 7.0.1; CreatedOnToolsVersion = 7.0.1;
DevelopmentTeam = W54V2VB863;
SystemCapabilities = { SystemCapabilities = {
com.apple.BackgroundModes = { com.apple.BackgroundModes = {
enabled = 0; enabled = 0;
...@@ -2850,8 +2855,8 @@ ...@@ -2850,8 +2855,8 @@
baseConfigurationReference = 6C6D8B0ECF8531E34D0DFF6B /* Pods.debug.xcconfig */; baseConfigurationReference = 6C6D8B0ECF8531E34D0DFF6B /* Pods.debug.xcconfig */;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer: Fanfan Cui (7S27LB84E2)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Fanfan Cui (7S27LB84E2)";
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
GCC_PREFIX_HEADER = "$(SRCROOT)/redstar/redstar.pch"; GCC_PREFIX_HEADER = "$(SRCROOT)/redstar/redstar.pch";
INFOPLIST_FILE = redstar/Info.plist; INFOPLIST_FILE = redstar/Info.plist;
...@@ -2871,8 +2876,8 @@ ...@@ -2871,8 +2876,8 @@
baseConfigurationReference = 13B0DDED3E0E584D79B395CF /* Pods.release.xcconfig */; baseConfigurationReference = 13B0DDED3E0E584D79B395CF /* Pods.release.xcconfig */;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Distribution: Shanghai Gomore Information Technology Co.,Ltd";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Shanghai Gomore Information Technology Co.,Ltd";
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
GCC_PREFIX_HEADER = "$(SRCROOT)/redstar/redstar.pch"; GCC_PREFIX_HEADER = "$(SRCROOT)/redstar/redstar.pch";
INFOPLIST_FILE = redstar/Info.plist; INFOPLIST_FILE = redstar/Info.plist;
......
...@@ -10,26 +10,22 @@ ...@@ -10,26 +10,22 @@
#import "LoginViewController.h" #import "LoginViewController.h"
#import "RootTabBarController.h" #import "RootTabBarController.h"
#import "APService.h" #import "APService.h"
#import "MobClick.h"
@interface AppDelegate () @interface AppDelegate ()
@end @end
#define UMENG_APPKEY @"56dcef9867e58e92640010da"
@implementation AppDelegate @implementation AppDelegate
- (void)umengTrack {
//友盟 56dcef9867e58e92640010da
[MobClick startWithAppkey:UMENG_APPKEY reportPolicy:(ReportPolicy) REALTIME channelId:nil];
// [MobClick setCrashReportEnabled:NO]; // 如果不需要捕捉异常,注释掉此行
[MobClick setLogEnabled:YES]; // 打开友盟sdk调试,注意Release发布时需要注释掉此行,减少io消耗
}
- (void)jiGuangPushWithOptions:(NSDictionary *)launchOptions {
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions // 通知
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
[[NSUserDefaults standardUserDefaults] setObject:@(10) forKey:@"requestNumber"];
// 设置根控制器
LoginViewController *loginVC = [[LoginViewController alloc] init];
self.window.rootViewController = loginVC;
// Required // Required
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
...@@ -57,6 +53,37 @@ ...@@ -57,6 +53,37 @@
categories:nil]; categories:nil];
} }
[APService setupWithOption:launchOptions]; [APService setupWithOption:launchOptions];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[_window makeKeyAndVisible];
[[NSUserDefaults standardUserDefaults] setObject:@(10) forKey:@"requestNumber"];
// 设置根控制器
LoginViewController *loginVC = [[LoginViewController alloc] init];
self.window.rootViewController = loginVC;
//友盟
[self umengTrack];
//推送
[self jiGuangPushWithOptions:launchOptions];
Class cls = NSClassFromString(@"UMANUtil");
SEL deviceIDSelector = @selector(openUDIDString);
NSString *deviceID = nil;
if(cls && [cls respondsToSelector:deviceIDSelector]){
deviceID = [cls performSelector:deviceIDSelector];
}
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@{@"oid" : deviceID}
options:NSJSONWritingPrettyPrinted
error:nil];
NSLog(@"%@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
return YES; return YES;
} }
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#define Url_h #define Url_h
// url 测试环境 // url 测试环境
#define kRedStarURL @"http://218.244.151.129:7580/" // #define kRedStarURL @"http://218.244.151.129:7580/"
// 正式环境 // 正式环境
// #define kRedStarURL @"http://219.235.234.225:7580/" // #define kRedStarURL @"http://219.235.234.225:7580/"
// 最新正式环境 // 最新正式环境
// #define kRedStarURL @"http://219.235.234.212:7580/" #define kRedStarURL @"http://219.235.234.212:7580/"
// 检查更新 // 检查更新
#define kCheckUpdateURL @"redstar-server/rest/ipapk?type=ipa" #define kCheckUpdateURL @"redstar-server/rest/ipapk?type=ipa"
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#import "NoDataView.h" #import "NoDataView.h"
#import <MJRefresh.h> #import <MJRefresh.h>
#import "MobClick.h"
#define kInspectListCell @"InspectListCellTableViewCell" #define kInspectListCell @"InspectListCellTableViewCell"
@interface InspectListViewController ()<UITableViewDelegate, UITableViewDataSource, ScreenTableDelegate , TaxisViewDelegate, InspectTableViewDelegate> @interface InspectListViewController ()<UITableViewDelegate, UITableViewDataSource, ScreenTableDelegate , TaxisViewDelegate, InspectTableViewDelegate>
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
@property (nonatomic, assign) NSInteger page; @property (nonatomic, assign) NSInteger page;
@property (nonatomic, strong) NoDataView *noDataView; @property (nonatomic, strong) NoDataView *noDataView;
@end @end
@implementation InspectListViewController @implementation InspectListViewController
...@@ -672,6 +671,9 @@ ...@@ -672,6 +671,9 @@
inspectTaskVC.store_uuid = taskList.store_uuid; inspectTaskVC.store_uuid = taskList.store_uuid;
inspectTaskVC.multiplier = (CGFloat)taskList.reportCount / taskList.questionCount; inspectTaskVC.multiplier = (CGFloat)taskList.reportCount / taskList.questionCount;
[self.navigationController pushViewController:inspectTaskVC animated:YES]; [self.navigationController pushViewController:inspectTaskVC animated:YES];
[MobClick event:@"didSelectInspectList"];
} }
// section高度 // section高度
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#import "SearchViewController.h" #import "SearchViewController.h"
#import "LookReportDetailViewController.h" #import "LookReportDetailViewController.h"
#import "MobClick.h"
typedef NSComparisonResult (^NSComparator)(id obj1, id obj2); typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UITextFieldDelegate, RankListHeaderDelegate> @interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UITextFieldDelegate, RankListHeaderDelegate>
...@@ -212,8 +213,11 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2); ...@@ -212,8 +213,11 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
self.navigationController.navigationBar.hidden = YES; self.navigationController.navigationBar.hidden = YES;
[self.tableView.mj_header beginRefreshing]; [self.tableView.mj_header beginRefreshing];
[MobClick beginLogPageView:@"MobClick Home"];
} }
- (void)viewDidAppear:(BOOL)animated - (void)viewDidAppear:(BOOL)animated
{ {
[super viewDidAppear:animated]; [super viewDidAppear:animated];
...@@ -221,7 +225,10 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2); ...@@ -221,7 +225,10 @@ typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
[self.tabBarController.tabBar setHidden:NO]; [self.tabBarController.tabBar setHidden:NO];
} }
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[MobClick endLogPageView:@"MobClick Home"];
}
#pragma mark - 刷新数据 #pragma mark - 刷新数据
- (void)refreshAllData - (void)refreshAllData
{ {
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.1.1</string> <string>1.0.5</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.1.1</string> <string>1.0.5</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment