开发者

Prompting the user to logon for encrypted documents

I have encrypted documents. After unarchiving each document, I need to prompt the user to enter the document password from a logon sheet. I have means to validate password entry against file contents (this part is done). If the password is incorrect the document shall be closed. If the passwo开发者_C百科rd is correct the document window shall be presented with document contents.

When I attempt to load the logon sheet (via its controller) in the document's windowControllerDidLoadNib method I have unrecognized selector error as shown below:

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];

    if (!newPasswordController){
        newPasswordController = [[NewPasswordController alloc] init];
        newPasswordSheet = [newPasswordController window];
    }
    [NSApp beginSheet:newPasswordSheet modalForWindow:[self window]
        modalDelegate:self
       didEndSelector:@selector(didNewPasswordEnd:returnCode:contextInfo:) 
          contextInfo:nil];

}

[_NSControllerObjectProxy copyWithZone:]: unrecognized selector sent to instance 

The method [NewPasswordController init] is implemented as follows:

-(id)init
{
    self = [super initWithWindowNibName:@"NewPassword"];
    if (self) {
    }
    return self;
}

where the logon sheet nib file is called NewPassword.

I wonder what went wrong. What is the best way to solve this problem?


Aside from unrecognized selector issue (which I left with Apple) I managed to address the original issue Prompting the user to logon for encrypted documents and here is the solution.

Note every document is password protected and they could potentially respond to different passwords (so the issue is not 'password protected application' but 'password protected documents').

Simply inject the following code when we are about to read document contents to pop up an application modal window to verify the document password:

- (BOOL)readFromData:(NSData *)data 
        ofType:(NSString *)typeName 
        error:(NSError **)outError 
{
   PasswordController *passwordController = [[PasswordController alloc] init];
   NSWindow *passwordSheet = [passwordController window];

   NSApplication* app = [NSApplication sharedApplication];
   NSInteger iret = [app runModalForWindow:passwordSheet];
   NSLog(@"password dialog returned = %ld", iret);
   if (iret != 0)
   {
       [app stop:self];
       return NO;
   }
   [passwordController release];
   ...

You may also pop up another kind of window when the document is saved the first time in dataOfType, forcing the user to set the document's password.

This issue is answered now.


The issue unrecognized selector was resolved after I constructed the xib file from scratch. This indicates a serious problem though concerning IB in XCode 4, as properties of the sheet and steps taken to create bindings, key-payths etc seemed identical in both cases. Something I have done during interface construction from IB caused a corruption in the xib file in my first attempt.

I'll leave it to forum administration to delete or keep this issue. If it is value to anyone I'll file a bug report with Apple (see below)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜