Annotation Author Name

Starting with PSPDFKit for iOS 4, we’ll ask for the author name before the first annotation is created.

This behavior can be disabled via setting shouldAskForAnnotationUsername to false in PDFConfiguration.

PSPDFKit uses various heuristics to suggest a suitable default name.

Using the UsernameHelper API

You also make use of our UsernameHelper API to show an alert asking for the default annotation author name to be used. You can do so by making a call to UsernameHelper.ask(forDefaultAnnotationUsernameIfNeeded:completionBlock:). This requires a PDFViewController object as a method argument, which the method uses to display the alert:

Copy
1
2
3
4
5
let controller: PDFViewController = ... // Currently displaying `PDFViewController`.
...
UsernameHelper.ask(forDefaultAnnotationUsernameIfNeeded: controller) { enteredUsername in
  // Do something with the entered username.
}
Copy
1
2
3
4
5
PSPDFViewController *controller = ... // Currently displaying `PSPDFViewController`.
...
[PSPDFUsernameHelper askForDefaultAnnotationUsernameIfNeeded:controller completionBlock:^(NSString *enteredUserName) {
  // Do something with the entered username.
}];

The entered username value is then stored in the UsernameHelper.defaultAnnotationUsername. This property uses NSUserDefaults for storage against the PSPDFDocumentDefaultAnnotationUsernameKey key.

You can use the UsernameHelper.isDefaultAnnotationUserNameSet API to check whether or not a username is already set.

ℹ️ Note: The username alert is only shown if an existing UsernameHelper.defaultAnnotationUsername isn’t set and the shouldAskForAnnotationUsername property of the PDFConfiguration object used to create the PDFViewController sent to the method isn’t false.

If you want to ask for the username regardless of a default name being set already, please clear the UsernameHelper.defaultAnnotationUsername value before calling the UsernameHelper API to ask for the user name.

Document-Specific Author Name

The author name set with the above method is used at a global level for all documents. PSPDFKit also allows you to change the author name specific to a document. To do so, simply update the defaultAnnotationUsername property of the Document instance to your desired author name:

1
2
let document = ... // Your document.
document.defaultAnnotationUsername = "Document Specific Author Name"
1
2
PSPDFDocument *document = ... // Your document.
document.defaultAnnotationUsername = "Document Specific Author Name";