Skip to content

Commit

Permalink
Update the Example of WebP coder for iOS/macOS/tvOS/watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dreampiggy committed Jul 3, 2020
1 parent 62a6ab8 commit 7bfd67a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Examples/SDWebImage Demo/AppDelegate.m
Expand Up @@ -10,6 +10,7 @@
#import "MasterViewController.h"

#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@implementation AppDelegate

Expand All @@ -24,6 +25,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
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.
Expand Down
4 changes: 0 additions & 4 deletions Examples/SDWebImage Demo/MasterViewController.m
Expand Up @@ -9,7 +9,6 @@
#import "MasterViewController.h"
#import "DetailViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface MyCustomTableViewCell : UITableViewCell

Expand Down Expand Up @@ -52,9 +51,6 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB
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";
Expand Down
11 changes: 11 additions & 0 deletions Examples/SDWebImage OSX Demo/AppDelegate.m
Expand Up @@ -8,6 +8,9 @@

#import "AppDelegate.h"

#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface AppDelegate ()

@end
Expand All @@ -16,6 +19,14 @@ @implementation AppDelegate

- (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 {
Expand Down
3 changes: 0 additions & 3 deletions Examples/SDWebImage OSX Demo/ViewController.m
Expand Up @@ -8,7 +8,6 @@

#import "ViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface ViewController ()

Expand All @@ -25,8 +24,6 @@ @implementation ViewController
- (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;
Expand Down
12 changes: 12 additions & 0 deletions Examples/SDWebImage TV Demo/AppDelegate.m
Expand Up @@ -8,6 +8,9 @@

#import "AppDelegate.h"

#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface AppDelegate ()

@end
Expand All @@ -17,6 +20,15 @@ @implementation AppDelegate

- (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;
}

Expand Down
2 changes: 0 additions & 2 deletions Examples/SDWebImage TV Demo/ViewController.m
Expand Up @@ -8,7 +8,6 @@

#import "ViewController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>

@interface ViewController ()

Expand All @@ -25,7 +24,6 @@ @implementation ViewController
- (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"]];
Expand Down
11 changes: 11 additions & 0 deletions Examples/SDWebImage Watch Demo Extension/ExtensionDelegate.m
Expand Up @@ -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 {
Expand Down
Expand Up @@ -8,8 +8,6 @@

#import "InterfaceController.h"
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>


@interface InterfaceController()

Expand All @@ -27,7 +25,6 @@ - (void)awakeWithContext:(id)context {
[super awakeWithContext:context];

// Configure interface objects here.
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
}

- (void)willActivate {
Expand Down

0 comments on commit 7bfd67a

Please sign in to comment.