PSPDFUsernameHelper
Objective-C
@interface PSPDFUsernameHelper : NSObject
Swift
class UsernameHelper : NSObject
A helper that can be used to present a dialog, allowing the user to specify the annotation author name.
-
Access or set the default annotation username.
This property uses
UserDefaults
for storage (thePSPDFDocumentDefaultAnnotationUsernameKey
key).- The default will be nil on iOS 16 and later.
- The default will be based on the device name on iOS 15 and earlier.
- The default will be the same as the user account name on Mac Catalyst.
These default values are also the value that will be used if the property is reset by setting it to
nil
.Note
The name set here will be used as the default value ofPSPDFDocument.defaultAnnotationUsername
for newly created documents. Updating this value will not update the value on existing documents.Declaration
Objective-C
@property (class, nonatomic, nullable) NSString *defaultAnnotationUsername;
Swift
class var defaultAnnotationUsername: String? { get set }
-
Checks for
PSPDFDocumentDefaultAnnotationUsernameKey
.Declaration
Objective-C
@property (class, nonatomic, readonly) BOOL isDefaultAnnotationUserNameSet;
Swift
class var isDefaultAnnotationUserNameSet: Bool { get }
-
Asks for the default new annotation username.
This will only display UI if enabled in the controller configuration and if the username is not already set.
Use this call if you’re presenting a custom annotation creation UI (e.g., a custom toolbar). Present your UI / toolbar inside the completion block. The behavior above ensures that the UI action is not performed if the dialog is canceled.
Note
The
completionBlock
will not be called if the dialog is already visible or if the user cancels it without confirming.Declaration
Objective-C
+ (void)askForDefaultAnnotationUsernameIfNeeded: (nonnull PSPDFViewController *)pdfViewController completionBlock: (nonnull void (^)(NSString *_Nullable)) completionBlock;
Swift
class func ask(forDefaultAnnotationUsernameIfNeeded pdfViewController: PSPDFViewController, completionBlock: @escaping (String?) -> Void)
Parameters
pdfViewController
The view controller to use as the presenting view controller.
completionBlock
Called when the user confirms the username and dismisses the dialog.
-
Asks for a new default username on the provided view controller.
Note
The
completionBlock
will not be called if the dialog is already visible or if the user cancels it without confirming.See
askForDefaultAnnotationUsernameIfNeeded:completionBlock:
Declaration
Objective-C
- (void) askForDefaultAnnotationUsername:(nonnull UIViewController *)viewController suggestedName:(nullable NSString *)suggestedName completionBlock: (nonnull void (^)(NSString *_Nonnull))completionBlock;
Swift
func ask(forDefaultAnnotationUsername viewController: UIViewController, suggestedName: String?, completionBlock: @escaping (String) -> Void)
Parameters
viewController
The view controller to use as the presenting view controller.
suggestedName
A username to be pre-filled in the dialog. If
nil
we’ll try to guess the username.completionBlock
Called when the user confirms the username and dismisses the dialog.