diff --git a/CHANGELOG-iOS.md b/CHANGELOG-iOS.md index a91cbcc..e7ab4da 100644 --- a/CHANGELOG-iOS.md +++ b/CHANGELOG-iOS.md @@ -1,5 +1,9 @@ # Facebook In-App Notifications for iOS Changelog +## [1.0.2] - 2016-12-09 +### Added +- Added support for loading images using SDWebImage instead of using the internal cache loader + ## [1.0.1] - 2016-05-10 ### Added @@ -18,4 +22,4 @@ View all issues and pull requests associated with this release [here](https://gi Initial Release -[1.0.1]: (https://github.com/facebook/FBNotifications/releases/tag/ios-1.0.1) \ No newline at end of file +[1.0.1]: (https://github.com/facebook/FBNotifications/releases/tag/ios-1.0.1) diff --git a/FBNotifications.podspec b/FBNotifications.podspec index 87501d7..be30e2b 100644 --- a/FBNotifications.podspec +++ b/FBNotifications.podspec @@ -1,19 +1,21 @@ Pod::Spec.new do |s| s.name = 'FBNotifications' - s.version = '1.0.1' + s.version = '1.0.2' s.license = { :type => 'Facebook Platform License', :file => 'LICENSE' } s.summary = 'Facebook In-App Notifications Framework' s.homepage = 'https://developers.facebook.com/products/analytics' s.authors = { 'Nikita Lutsenko' => 'nlutsenko@me.com' } - s.source = { :git => 'https://github.com/facebook/FBNotifications.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/MobileConcepts/FBNotifications.git', :tag => s.version.to_s } s.requires_arc = true + s.dependency 'SDWebImage' + s.ios.deployment_target = '8.0' s.source_files = 'iOS/FBNotifications/FBNotifications/**/*.{h,m}' s.public_header_files = 'iOS/FBNotifications/FBNotifications/*.h' - s.frameworks = 'ImageIO', 'MobileCoreServices' + s.frameworks = 'ImageIO', 'MobileCoreServices','SDWebImage' end diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m index 5c0e826..a5ee58b 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m @@ -98,6 +98,11 @@ - (NSData *)cachedDataForContentURL:(NSURL *)url { } - (BOOL)hasCachedContentForURLs:(nullable NSSet *)urls { +#if __has_include() + //We let SDWebImage handle the caching + return YES; +#else + for (NSURL *url in urls) { NSString *cacheKey = [self _cacheKeyForContentURL:url]; if (![self _hasCachedDataForContentWithCacheKey:cacheKey]) { @@ -105,6 +110,7 @@ - (BOOL)hasCachedContentForURLs:(nullable NSSet *)urls { } } return YES; +#endif } - (BOOL)_hasCachedDataForContentWithCacheKey:(NSString *)key { diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.h b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.h index 5fb5ac6..27357c5 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.h +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.h @@ -27,8 +27,10 @@ extern NSString *const FBNImageAssetType; @interface FBNImageAsset : NSObject @property (nonatomic, strong, readonly) UIImage *image; +@property (nonatomic, strong, readonly) NSURL *url; - (instancetype)initWithImage:(UIImage *)image; +- (instancetype)initWithURL:(NSURL *)url; - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.m index a87ae7c..309c44e 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAsset.m @@ -37,6 +37,15 @@ - (instancetype)initWithImage:(UIImage *)image { return self; } +- (instancetype)initWithURL:(NSURL *)url { + self = [super init]; + if (!self) return self; + + + _url = url; + + return self; +} ///-------------------------------------- #pragma mark - FBNAsset diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetController.m index f115e9e..78c0e9d 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetController.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetController.m @@ -39,12 +39,19 @@ - (void)loadAssetFromDictionary:(NSDictionary *)dictionary } NSURL *url = [NSURL URLWithString:dictionary[@"url"]]; +#if __has_include() + //We let SDWebImage handle the caching + FBNImageAsset *asset = [[FBNImageAsset alloc] initWithURL:url]; + completion(asset); + +#else dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSData *data = [cache cachedDataForContentURL:url]; UIImage *image = [[UIImage alloc] initWithData:data]; FBNImageAsset *asset = [[FBNImageAsset alloc] initWithImage:image]; completion(asset); }); +#endif } - (nullable NSSet *)cacheURLsForAssetDictionary:(NSDictionary *)dictionary { diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m index c7a8226..c0387b2 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m @@ -20,6 +20,10 @@ #import "FBNImageAsset.h" +#if __has_include() + #import +#endif + NS_ASSUME_NONNULL_BEGIN @interface FBNImageAssetViewController () @@ -48,7 +52,13 @@ - (instancetype)initWithAsset:(FBNImageAsset *)asset { ///-------------------------------------- - (void)loadView { +#if __has_include() + UIImageView *view = [[UIImageView alloc] init]; + [view setShowActivityIndicatorView:YES]; + [view sd_setImageWithPreviousCachedImageWithURL:self.asset.url placeholderImage:nil options:0 progress:nil completed:nil]; +#else UIImageView *view = [[UIImageView alloc] initWithImage:self.asset.image]; +#endif view.contentMode = UIViewContentModeScaleAspectFill; self.view = view; }