问题
I am using PDF kit framework to display/Edit pdf files. Its broken badly on macOS 10.12. Sometimes password protected files do not display password field and sometimes password field is visible in normal file.
回答1:
I am able to fix this using undocumented APIs. Its issue related to hide/unhide password view.
/*
From class dump of pdf kit
@interface PDFPasswordViewController : NSViewController
{
NSTextField *_passwordField;
NSTextField *_passwordPrompt;
NSTextField *_passwordInstruction;
NSView *_passwordView;
PDFView *_pdfView;
}
- (void).cxx_destruct;
- (void)_commonInit;
- (void)passwordEntered:(id)arg1;
- (void)setPDFView:(id)arg1;
- (void)loadView;
@end
*/
/*
@private
PDFViewPrivate* _private;
Available in PDFView.h file
*/
id PDFViewPrivate = [self.pdfView valueForKey:@"_private"];
if (PDFViewPrivate)
{
NSViewController *passwordViewController = [PDFViewPrivate valueForKey:@"passwordViewController"];
NSView *passwordView = [passwordViewController valueForKey:@"_passwordView"];
if (self.pdfView.document.isLocked)
{
NSTextField *passwordField = [passwordViewController valueForKey:@"_passwordField"];
// Reset last password
[passwordField setStringValue:@""];
// Add password view
passwordView.hidden = NO;
}
else
{
passwordView.hidden = YES;
}
}
PDFPasswordViewController
is only available on 10.12
来源:https://stackoverflow.com/questions/42173471/password-field-not-visible-on-password-protected-pdf