Skip to content

Commit 9af5988

Browse files
authored
Merge pull request #12 from SDWebImage/change_compatible_with_ph_scheme_react_native
Change to use the ph:// URL format, to compatible with react-native-cameraroll
2 parents 076f7b5 + 3c75018 commit 9af5988

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DEPENDENCIES:
99
- SDWebImagePhotosPlugin (from `../`)
1010

1111
SPEC REPOS:
12-
https://github.com/cocoapods/specs.git:
12+
https://github.com/CocoaPods/Specs.git:
1313
- Expecta
1414
- SDWebImage
1515

@@ -24,4 +24,4 @@ SPEC CHECKSUMS:
2424

2525
PODFILE CHECKSUM: 60756e45d1da564a14e0e1964ffd639deadc2855
2626

27-
COCOAPODS: 1.7.5
27+
COCOAPODS: 1.8.4

SDWebImagePhotosPlugin/Classes/NSURL+SDWebImagePhotosPlugin.m

+7-16
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#import <Photos/Photos.h>
1212
#import <objc/runtime.h>
1313

14-
static NSString * _Nonnull const SDWebImagePhotosURLHostAsset = @"asset";
15-
1614
@implementation NSURL (SDWebImagePhotosPlugin)
1715

1816
- (BOOL)sd_isPhotosURL {
@@ -27,16 +25,12 @@ - (NSString *)sd_assetLocalIdentifier {
2725
if (asset) {
2826
return asset.localIdentifier;
2927
}
30-
NSString *host = self.host;
31-
if (![SDWebImagePhotosURLHostAsset isEqualToString:host]) {
32-
return nil;
33-
}
34-
NSString *path = self.path;
35-
if (path.length <= 1) {
28+
NSString *urlString = self.absoluteString;
29+
NSString *prefix = [NSString stringWithFormat:@"%@://", SDWebImagePhotosScheme];
30+
if (urlString.length <= prefix.length) {
3631
return nil;
3732
}
38-
39-
return [[path substringFromIndex:1] stringByRemovingPercentEncoding];
33+
return [urlString stringByReplacingOccurrencesOfString:prefix withString:@""];
4034
}
4135

4236
- (PHAsset *)sd_asset {
@@ -51,12 +45,9 @@ + (instancetype)sd_URLWithAssetLocalIdentifier:(NSString *)identifier {
5145
if (!identifier) {
5246
return nil;
5347
}
54-
// photos://asset/123
55-
NSURLComponents *components = [[NSURLComponents alloc] initWithString:[NSString stringWithFormat:@"%@://%@/", SDWebImagePhotosScheme, SDWebImagePhotosURLHostAsset]];
56-
NSString *encodedPath = [identifier stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
57-
components.path = [components.path stringByAppendingString:encodedPath];
58-
59-
return components.URL;
48+
// ph://F2A9F582-BA45-4308-924E-6D146B784A09/L0/001
49+
NSString *prefix = [NSString stringWithFormat:@"%@://", SDWebImagePhotosScheme];
50+
return [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", prefix, identifier]];
6051
}
6152

6253
+ (instancetype)sd_URLWithAsset:(PHAsset *)asset {

SDWebImagePhotosPlugin/Classes/SDWebImagePhotosDefine.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import "SDWebImagePhotosDefine.h"
1010

11-
NSString * _Nonnull const SDWebImagePhotosScheme = @"photos";
11+
NSString * _Nonnull const SDWebImagePhotosScheme = @"ph";
1212
const CGSize SDWebImagePhotosLoaderPixelSize = {.width = 0, .height = 0};
1313
const CGSize SDWebImagePhotosLoaderPointSize = {.width = -1, .height = -1};
1414
const int64_t SDWebImagePhotosProgressExpectedSize = 100LL;

0 commit comments

Comments
 (0)