Update the Example of WebP coder for iOS/macOS/tvOS/watchOS

This commit is contained in:
DreamPiggy 2020-07-03 12:48:50 +08:00
parent 62a6ab8e71
commit 7bfd67a94f
8 changed files with 44 additions and 12 deletions

View File

@ -10,6 +10,7 @@
#import "MasterViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@implementation AppDelegate
@ -24,6 +25,15 @@
NSString *fileName = [[SDImageCache sharedImageCache] cachePathForKey:key].lastPathComponent;
return [bundledPath stringByAppendingPathComponent:fileName.stringByDeletingPathExtension];
};
if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) {
// iOS 14 supports WebP built-in
[[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]];
} else {
// iOS 13 does not supports WebP, use third-party codec
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}
[[SDImageCodersManager sharedManager] addCoder:[SDImageHEICCoder sharedCoder]]; // For HEIC static/animated image. Animated image is new introduced in iOS 13, but it contains performance issue for now.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// Override point for customization after application launch.

View File

@ -9,7 +9,6 @@
#import "MasterViewController.h"
#import "DetailViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface MyCustomTableViewCell : UITableViewCell
@ -52,9 +51,6 @@
target:self
action:@selector(flushCache)];
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]]; // For WebP static/animated image
[[SDImageCodersManager sharedManager] addCoder:[SDImageHEICCoder sharedCoder]]; // For HEIC static/animated image. Animated image is new introduced in iOS 13, but it contains performance issue for now.
// HTTP NTLM auth example
// Add your NTLM image url to the array below and replace the credentials
[SDWebImageDownloader sharedDownloader].config.username = @"httpwatch";

View File

@ -8,6 +8,9 @@
#import "AppDelegate.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface AppDelegate ()
@end
@ -16,6 +19,14 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) {
// iOS 14 supports WebP built-in
[[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]];
} else {
// iOS 13 does not supports WebP, use third-party codec
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}
[[SDImageCodersManager sharedManager] addCoder:[SDImageHEICCoder sharedCoder]]; // For HEIC static/animated image. Animated image is new introduced in iOS 13, but it contains performance issue for now.
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {

View File

@ -8,7 +8,6 @@
#import "ViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface ViewController ()
@ -25,8 +24,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
// For animated GIF rendering, set `animates` to YES or will only show the first frame
self.imageView2.animates = YES; // `SDAnimatedImageRep` can be used for built-in `NSImageView` to support better GIF & APNG rendering as well. No need `SDAnimatedImageView`
self.imageView4.animates = YES;

View File

@ -8,6 +8,9 @@
#import "AppDelegate.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface AppDelegate ()
@end
@ -17,6 +20,15 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) {
// iOS 14 supports WebP built-in
[[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]];
} else {
// iOS 13 does not supports WebP, use third-party codec
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}
[[SDImageCodersManager sharedManager] addCoder:[SDImageHEICCoder sharedCoder]]; // For HEIC static/animated image. Animated image is new introduced in iOS 13, but it contains performance issue for now.
return YES;
}

View File

@ -8,7 +8,6 @@
#import "ViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface ViewController ()
@ -25,7 +24,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
[self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"]];
[self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]];

View File

@ -8,10 +8,21 @@
#import "ExtensionDelegate.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@implementation ExtensionDelegate
- (void)applicationDidFinishLaunching {
// Perform any final initialization of your application.
if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) {
// iOS 14 supports WebP built-in
[[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]];
} else {
// iOS 13 does not supports WebP, use third-party codec
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}
[[SDImageCodersManager sharedManager] addCoder:[SDImageHEICCoder sharedCoder]]; // For HEIC static/animated image. Animated image is new introduced in iOS 13, but it contains performance issue for now.
}
- (void)applicationDidBecomeActive {

View File

@ -8,8 +8,6 @@
#import "InterfaceController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
@interface InterfaceController()
@ -27,7 +25,6 @@
[super awakeWithContext:context];
// Configure interface objects here.
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}
- (void)willActivate {