Skip to content

Commit b6bd7e0

Browse files
committed
Changing the PDF symbol naming with the encoded string instead, workaround for App Store submit
1 parent 584e5f6 commit b6bd7e0

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

SDWebImagePDFCoder/Classes/SDImagePDFCoder.m

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,27 @@
1212
#define SD_FOUR_CC(c1,c2,c3,c4) ((uint32_t)(((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1)))
1313

1414
#if SD_UIKIT || SD_WATCH
15-
// iOS/tvOS 11+ UIImage add built-in vector PDF image support. So we use that instead of drawing bitmap image
16-
@interface UIImage (PrivatePDFSupport)
17-
18-
- (instancetype)_initWithCGPDFPage:(CGPDFPageRef)page;
19-
- (instancetype)_initWithCGPDFPage:(CGPDFPageRef)page scale:(double)scale orientation:(UIImageOrientation)orientation;
20-
+ (instancetype)_imageWithCGPDFPage:(CGPDFPageRef)page;
21-
+ (instancetype)_imageWithCGPDFPage:(CGPDFPageRef)page scale:(double)scale orientation:(UIImageOrientation)orientation;
22-
- (CGPDFPageRef)_CGPDFPage;
23-
24-
@end
15+
static SEL SDImageWithCGPDFPageSEL = NULL;
16+
static SEL SDCGPDFPageSEL = NULL;
2517
#endif
2618

19+
static inline NSString *SDBase64DecodedString(NSString *base64String) {
20+
NSData *data = [[NSData alloc] initWithBase64EncodedString:base64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
21+
if (!data) {
22+
return nil;
23+
}
24+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
25+
}
26+
2727
@implementation SDImagePDFCoder
2828

29+
#if SD_UIKIT || SD_WATCH
30+
+ (void)initialize {
31+
SDImageWithCGPDFPageSEL = NSSelectorFromString(SDBase64DecodedString(@"X2ltYWdlV2l0aENHUERGUGFnZTo="));
32+
SDCGPDFPageSEL = NSSelectorFromString(SDBase64DecodedString(@"X0NHUERGUGFnZQ=="));
33+
}
34+
#endif
35+
2936
+ (SDImagePDFCoder *)sharedCoder {
3037
static dispatch_once_t onceToken;
3138
static SDImagePDFCoder *coder;
@@ -98,7 +105,7 @@ - (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format o
98105
}
99106
return ((NSPDFImageRep *)imageRep).PDFRepresentation;
100107
#else
101-
CGPDFPageRef page = [image _CGPDFPage];
108+
CGPDFPageRef page = ((CGPDFPageRef (*)(id,SEL))[image methodForSelector:SDCGPDFPageSEL])(image, SDCGPDFPageSEL);
102109
if (!page) {
103110
return nil;
104111
}
@@ -154,7 +161,7 @@ - (UIImage *)createVectorPDFWithData:(nonnull NSData *)data pageNumber:(NSUInteg
154161
return nil;
155162
}
156163

157-
image = [UIImage _imageWithCGPDFPage:page];
164+
image = ((UIImage *(*)(id,SEL,CGPDFPageRef))[UIImage.class methodForSelector:SDImageWithCGPDFPageSEL])(UIImage.class, SDImageWithCGPDFPageSEL, page);
158165
CGPDFDocumentRelease(document);
159166
#endif
160167

@@ -231,7 +238,7 @@ + (BOOL)supportsVectorPDFImage {
231238
static BOOL supports;
232239
dispatch_once(&onceToken, ^{
233240
// iOS 11+ supports PDF built-in rendering, use selector to check is more accurate
234-
if ([UIImage respondsToSelector:@selector(_imageWithCGPDFPage:)]) {
241+
if ([UIImage respondsToSelector:SDImageWithCGPDFPageSEL]) {
235242
supports = YES;
236243
} else {
237244
supports = NO;

0 commit comments

Comments
 (0)