11
11
#import < Photos/Photos.h>
12
12
#import < objc/runtime.h>
13
13
14
- static NSString * _Nonnull const SDWebImagePhotosURLHostAsset = @" asset" ;
15
-
16
14
@implementation NSURL (SDWebImagePhotosPlugin)
17
15
18
16
- (BOOL )sd_isPhotosURL {
@@ -27,16 +25,12 @@ - (NSString *)sd_assetLocalIdentifier {
27
25
if (asset) {
28
26
return asset.localIdentifier ;
29
27
}
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 ) {
36
31
return nil ;
37
32
}
38
-
39
- return [[path substringFromIndex: 1 ] stringByRemovingPercentEncoding ];
33
+ return [urlString stringByReplacingOccurrencesOfString: prefix withString: @" " ];
40
34
}
41
35
42
36
- (PHAsset *)sd_asset {
@@ -51,12 +45,9 @@ + (instancetype)sd_URLWithAssetLocalIdentifier:(NSString *)identifier {
51
45
if (!identifier) {
52
46
return nil ;
53
47
}
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]];
60
51
}
61
52
62
53
+ (instancetype )sd_URLWithAsset : (PHAsset *)asset {
0 commit comments