On Oct 9, 2014, at 13:44 , Matthew LeRoy <mle...@minitab.com> wrote: > so -[NSDocumentController beginOpenPanelWithCompletionHandler:] is what I > would be using.
> Hmm, OK. So where do I provide the custom completion handler? Ah, I see, I thought you were already *providing* a completion handler somewhere, but I guess you’re not. In that case, I think you would override -[NSDocumentController openDocumentWithContentsOfURL:display:completionHandler:], like this: - (void)openDocumentWithContentsOfURL:(NSURL *)url display:(BOOL)displayDocument completionHandler:(void (^)(NSDocument*document, BOOL documentWasAlreadyOpen, NSError *error))completionHandler { if ([self typeForContentsOfURL: url …] != myOldType [super openDocumentWithContentsOfURL: url display: displayDocument completionHandler: completionHandler]; else dispatch_async (dispatch_get_main_queue (), ^{ [SomeClass verifyPasswordForURL: url completionHandler: ^(NSError* error) { if (error == nil) [super openDocumentWithContentsOfURL: url display: displayDocument completionHandler: completionHandler]; else if (completionHandler != nil) completionHandler (nil, NO, error); }]; }); } Just make sure that the password verification (which is invoked on the main thread) doesn’t eventually invoke its completion handler on a background thread — or if it must, then wrap the innermost if/else in another dispatch_async (dispatch_get_main_queue (), …) block. With this code (warning: written in Mail) you’re getting all the normal document behavior, and reporting a password verification failure through the normal document mechanism. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com