From e866db551b16451992e385d80a6848a437373b1a Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:17:42 +0100 Subject: [PATCH 01/13] Add files via upload --- .../Internal/Asset/FBNImageAssetController.m | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m new file mode 100644 index 0000000..b047a5f --- /dev/null +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m @@ -0,0 +1,89 @@ +// Copyright (c) 2016-present, Facebook, Inc. All rights reserved. +// +// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, +// copy, modify, and distribute this software in source code or binary form for use +// in connection with the web services and APIs provided by Facebook. +// +// As with any software that integrates with the Facebook platform, your use of +// this software is subject to the Facebook Developer Principles and Policies +// [http://developers.facebook.com/policy/]. This copyright notice shall be +// included in all copies or substantial portions of the software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#import "FBNImageAssetController.h" + +#import "FBNImageAsset.h" +#import "FBNAssetContentCache.h" + +#if __has_include() +#import +#endif + +NS_ASSUME_NONNULL_BEGIN + +@implementation FBNImageAssetController + +///-------------------------------------- +#pragma mark - FBNAssetController +///-------------------------------------- + +- (nullable id)assetFromDictionary:(NSDictionary *)dictionary contentCache:(FBNAssetContentCache *)cache { + if (![self isValidAssetDictionary:dictionary]) { + return nil; + } + + NSURL *url = [NSURL URLWithString:dictionary[@"url"]]; + +#if __has_include() + return [[FBNImageAsset alloc] initWithURL:url]; +#else + /*Without SDWebImage*/ + UIImage *image = [[UIImage alloc] initWithData:[cache cachedDataForContentURL:url]]; + return [[FBNImageAsset alloc] initWithImage:nil]; +#endif + +} + +- (nullable NSSet *)cacheURLsForAssetDictionary:(NSDictionary *)dictionary { + if (![self isValidAssetDictionary:dictionary]) { + return nil; + } + + NSURL *url = [NSURL URLWithString:dictionary[@"url"]]; + return (url ? [NSSet setWithObject:url] : nil); +} + +- (BOOL)isValidAssetDictionary:(NSDictionary *)dictionary { + if (![dictionary isKindOfClass:[NSDictionary class]] || + ![dictionary[@"_type"] isEqualToString:FBNImageAssetType] || + ![dictionary[@"url"] isKindOfClass:[NSString class]]) { + return NO; + } + return YES; +} + +- (nullable UIView *)viewForAsset:(id)asset { + FBNImageAsset *imageAsset = (FBNImageAsset *)asset; + + +#if __has_include() + UIImageView *view = [[UIImageView alloc] init]; + [view setShowActivityIndicatorView:YES]; + [view sd_setImageWithPreviousCachedImage:imageAsset.url]; +#else + UIImageView *view = [[UIImageView alloc] initWithImage:imageAsset.image]; +#endif + + view.contentMode = UIViewContentModeScaleAspectFill; + return view; +} + +@end + +NS_ASSUME_NONNULL_END From 546ab5719764d9abe35c2fffba15e883a8799c90 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:18:32 +0100 Subject: [PATCH 02/13] Delete FBNImageAssetController.m --- .../Internal/Asset/FBNImageAssetController.m | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m deleted file mode 100644 index b047a5f..0000000 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/FBNImageAssetController.m +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2016-present, Facebook, Inc. All rights reserved. -// -// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, -// copy, modify, and distribute this software in source code or binary form for use -// in connection with the web services and APIs provided by Facebook. -// -// As with any software that integrates with the Facebook platform, your use of -// this software is subject to the Facebook Developer Principles and Policies -// [http://developers.facebook.com/policy/]. This copyright notice shall be -// included in all copies or substantial portions of the software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -#import "FBNImageAssetController.h" - -#import "FBNImageAsset.h" -#import "FBNAssetContentCache.h" - -#if __has_include() -#import -#endif - -NS_ASSUME_NONNULL_BEGIN - -@implementation FBNImageAssetController - -///-------------------------------------- -#pragma mark - FBNAssetController -///-------------------------------------- - -- (nullable id)assetFromDictionary:(NSDictionary *)dictionary contentCache:(FBNAssetContentCache *)cache { - if (![self isValidAssetDictionary:dictionary]) { - return nil; - } - - NSURL *url = [NSURL URLWithString:dictionary[@"url"]]; - -#if __has_include() - return [[FBNImageAsset alloc] initWithURL:url]; -#else - /*Without SDWebImage*/ - UIImage *image = [[UIImage alloc] initWithData:[cache cachedDataForContentURL:url]]; - return [[FBNImageAsset alloc] initWithImage:nil]; -#endif - -} - -- (nullable NSSet *)cacheURLsForAssetDictionary:(NSDictionary *)dictionary { - if (![self isValidAssetDictionary:dictionary]) { - return nil; - } - - NSURL *url = [NSURL URLWithString:dictionary[@"url"]]; - return (url ? [NSSet setWithObject:url] : nil); -} - -- (BOOL)isValidAssetDictionary:(NSDictionary *)dictionary { - if (![dictionary isKindOfClass:[NSDictionary class]] || - ![dictionary[@"_type"] isEqualToString:FBNImageAssetType] || - ![dictionary[@"url"] isKindOfClass:[NSString class]]) { - return NO; - } - return YES; -} - -- (nullable UIView *)viewForAsset:(id)asset { - FBNImageAsset *imageAsset = (FBNImageAsset *)asset; - - -#if __has_include() - UIImageView *view = [[UIImageView alloc] init]; - [view setShowActivityIndicatorView:YES]; - [view sd_setImageWithPreviousCachedImage:imageAsset.url]; -#else - UIImageView *view = [[UIImageView alloc] initWithImage:imageAsset.image]; -#endif - - view.contentMode = UIViewContentModeScaleAspectFill; - return view; -} - -@end - -NS_ASSUME_NONNULL_END From bead92913b59ce99bfa99690f29c549384cb6256 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:43:54 +0100 Subject: [PATCH 03/13] Update FBNotifications.podspec Added SDWebImage dependency --- FBNotifications.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FBNotifications.podspec b/FBNotifications.podspec index 87501d7..09a3509 100644 --- a/FBNotifications.podspec +++ b/FBNotifications.podspec @@ -15,5 +15,5 @@ Pod::Spec.new do |s| 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 From b41625f19f4fcf43558975242fefaa0f71ab7a69 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:49:03 +0100 Subject: [PATCH 04/13] Update FBNotifications.podspec --- FBNotifications.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FBNotifications.podspec b/FBNotifications.podspec index 09a3509..079901b 100644 --- a/FBNotifications.podspec +++ b/FBNotifications.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| 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 From bc11928a6888fbba8cc1419c23937ef4b7c54b7b Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:49:17 +0100 Subject: [PATCH 05/13] Update FBNotifications.podspec --- FBNotifications.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FBNotifications.podspec b/FBNotifications.podspec index 079901b..ff20577 100644 --- a/FBNotifications.podspec +++ b/FBNotifications.podspec @@ -1,6 +1,6 @@ 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' From 0ce8c6a031663d2b90760de0611dbf55d608d374 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:49:57 +0100 Subject: [PATCH 06/13] Update FBNotifications.podspec --- FBNotifications.podspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FBNotifications.podspec b/FBNotifications.podspec index ff20577..be30e2b 100644 --- a/FBNotifications.podspec +++ b/FBNotifications.podspec @@ -10,6 +10,8 @@ Pod::Spec.new do |s| s.requires_arc = true + s.dependency 'SDWebImage' + s.ios.deployment_target = '8.0' s.source_files = 'iOS/FBNotifications/FBNotifications/**/*.{h,m}' From eba9f66e6e2edf9801623fe2efe53e8e3843c24b Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 11:59:47 +0100 Subject: [PATCH 07/13] Update CHANGELOG-iOS.md --- CHANGELOG-iOS.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) From adce5bd569bbf456fc2b0cb986de6d9c2b5e4175 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 12:05:03 +0100 Subject: [PATCH 08/13] Added support for lazy loading with SDWebImage --- .../FBNotifications/Internal/Asset/Image/FBNImageAsset.h | 2 ++ .../FBNotifications/Internal/Asset/Image/FBNImageAsset.m | 9 +++++++++ 2 files changed, 11 insertions(+) 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 From 39762c104e3c6adfc293da5a41f860d9b46da0d9 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 12:06:01 +0100 Subject: [PATCH 09/13] Added support for lazy loading using SDWebImage --- .../Internal/Asset/Image/FBNImageAssetController.m | 7 +++++++ 1 file changed, 7 insertions(+) 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 { From 6c59018b0bacd2b8b0a9b36c691842575bb67fbd Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 12:06:36 +0100 Subject: [PATCH 10/13] Added support for lazy loading using SDWebImage --- .../Internal/Asset/Image/FBNImageAssetViewController.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m index c7a8226..b9cccde 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:nil progress:nil completed:nil]; +#else UIImageView *view = [[UIImageView alloc] initWithImage:self.asset.image]; +#endif view.contentMode = UIViewContentModeScaleAspectFill; self.view = view; } From 595ce181102bea00cf0fa2011d9af5a457da13db Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 12:08:31 +0100 Subject: [PATCH 11/13] Addes support for lazy loading with SDWebImage --- .../Internal/Asset/Cache/FBNAssetContentCache.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m index 5c0e826..9fd91b6 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; + #endif + for (NSURL *url in urls) { NSString *cacheKey = [self _cacheKeyForContentURL:url]; if (![self _hasCachedDataForContentWithCacheKey:cacheKey]) { From 60f8a9ec8a3651898a2387bd2aa052a252dc76b5 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 12:33:42 +0100 Subject: [PATCH 12/13] Update FBNAssetContentCache.m --- .../Internal/Asset/Cache/FBNAssetContentCache.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m index 9fd91b6..a5ee58b 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Cache/FBNAssetContentCache.m @@ -98,10 +98,10 @@ - (NSData *)cachedDataForContentURL:(NSURL *)url { } - (BOOL)hasCachedContentForURLs:(nullable NSSet *)urls { - #if __has_include() +#if __has_include() //We let SDWebImage handle the caching return YES; - #endif +#else for (NSURL *url in urls) { NSString *cacheKey = [self _cacheKeyForContentURL:url]; @@ -110,6 +110,7 @@ - (BOOL)hasCachedContentForURLs:(nullable NSSet *)urls { } } return YES; +#endif } - (BOOL)_hasCachedDataForContentWithCacheKey:(NSString *)key { From 1b4be7c3f24934a26d0853806f29c51d109936c2 Mon Sep 17 00:00:00 2001 From: mobile concepst GmbH Date: Fri, 9 Dec 2016 13:52:26 +0100 Subject: [PATCH 13/13] Fixed a warning --- .../Internal/Asset/Image/FBNImageAssetViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m index b9cccde..c0387b2 100644 --- a/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m +++ b/iOS/FBNotifications/FBNotifications/Internal/Asset/Image/FBNImageAssetViewController.m @@ -55,7 +55,7 @@ - (void)loadView { #if __has_include() UIImageView *view = [[UIImageView alloc] init]; [view setShowActivityIndicatorView:YES]; - [view sd_setImageWithPreviousCachedImageWithURL:self.asset.url placeholderImage:nil options:nil progress:nil completed:nil]; + [view sd_setImageWithPreviousCachedImageWithURL:self.asset.url placeholderImage:nil options:0 progress:nil completed:nil]; #else UIImageView *view = [[UIImageView alloc] initWithImage:self.asset.image]; #endif