PSPDFInstantClientDelegate
Objective-C
@protocol PSPDFInstantClientDelegate <NSObject>
Swift
protocol InstantClientDelegate : NSObjectProtocol
The delegate of a PSPDFInstantClient
must adopt this protocol to be notified of download and authentication events.
Delegates that are interested in events around the sync cycle can also implement the optional methods listed in the
“Sync Events” section. For a more detailed explanation of the sync cycle of a document and its possible states, please
refer to the documentation on PSPDFInstantDocumentState
.
If you need multiple observers or are only interested in the events of a single document, you can use the notifications
posted by PSPDFInstantDocumentDescriptor
.
Note
Important: All methods in this protocol will be called on a background thread!-
Called when downloading a PDF file from the server finishes.
At this point the instances returned by
PSPDFInstantDocumentDescriptor.editableDocument
or-[PSPDFInstantDocumentDescriptor readOnlyDocument]
of this document descriptor will be fully usable.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient didFinishDownloadForDocumentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor;
Swift
func instantClient(_ instantClient: InstantClient, didFinishDownloadFor documentDescriptor: InstantDocumentDescriptor)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document whose download finished.
-
Called when downloading a PDF file from the server fails.
Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient documentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor didFailDownloadWithError:(nonnull NSError *)error;
Swift
func instantClient(_ instantClient: InstantClient, documentDescriptor: InstantDocumentDescriptor, didFailDownloadWithError error: Error)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document whose download failed.
error
The error that occurred.
-
Called when the document fails to authenticate with the PSPDFKit Server to synchronize annotations.
This typically means either the user no longer has access to the document or the JWT expired. Your own server should be able to say if the user still has access.
If the user still has access, obtain a new JWT from your server and call
-[PSPDFInstantDocumentDescriptor reauthenticateWithJWT:]
on the document descriptor. If the user no longer has access, consider stopping showing this document to the user and call-[PSPDFInstantDocumentDescriptor removeLocalStorageWithError:]
on the document descriptor.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient didFailAuthenticationForDocumentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor;
Swift
func instantClient(_ instantClient: InstantClient, didFailAuthenticationFor documentDescriptor: InstantDocumentDescriptor)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that failed authentication.
-
Called when a prior call to
-[PSPDFInstantDocumentDescriptor reauthenticateWithJWT:]
has completed successfully.The JWT that you passed into that method and which has been accepted is relayed back to you. The token would be safe to persist so that you can re-use it the next time your app launches.
Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient documentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>) documentDescriptor didFinishReauthenticationWithJWT:(nonnull NSString *)validJWT;
Swift
func instantClient(_ instantClient: InstantClient, documentDescriptor: InstantDocumentDescriptor, didFinishReauthenticationWithJWT validJWT: String)
Parameters
instantClient
The sender of the message.
validJWT
The JWT that has been used to authenticate the document.
documentDescriptor
The descriptor of the document that has been reauthenticated.
-
Called when a prior call to
-[PSPDFInstantDocumentDescriptor reauthenticateWithJWT:]
has failed.If authentication failed for any other reasons than a dropped connection and you chose to store a JWT for this document descriptor, you should delete the JWT when receiving this message.
Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient documentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>) documentDescriptor didFailReauthenticationWithError:(nonnull NSError *)error;
Swift
func instantClient(_ instantClient: InstantClient, documentDescriptor: InstantDocumentDescriptor, didFailReauthenticationWithError error: Error)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that could not be reauthenticated.
error
The an error detailing why reauthentication failed.
-
Called when the document begins a new sync cycle.
When listening for server changes, a sync cycle begins when changes from the server start coming in. Otherwise, a sync cycle begins when you call
-[PSPDFInstantDocumentDescriptor sync]
on an object that isn’t already syncing, or because of automatic sync of changes.
For more details on the sync cycle, please refer to the documentation ofPSPDFInstantDocumentState
.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient didBeginSyncForDocumentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor;
Swift
optional func instantClient(_ instantClient: InstantClient, didBeginSyncFor documentDescriptor: InstantDocumentDescriptor)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that has begun a new sync cycle.
-
Called when the document changes its sync state.
After
-instantClient:didBeginSyncForDocumentDescriptor:
, this method may be called multiple times during the sync cycle. The cycle continues until either-instantClient:didFinishSyncForDocumentDescriptor:
or-instantClient:documentDescriptor:didFailSyncWithError:
is called.
For more details on the sync cycle, please refer to the documentation ofPSPDFInstantDocumentState
.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient didChangeSyncStateForDocumentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor;
Swift
optional func instantClient(_ instantClient: InstantClient, didChangeSyncStateFor documentDescriptor: InstantDocumentDescriptor)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that changed its sync state.
-
Called when the sync cycle completes with an error.
The most likely reason is network failure or cancellation of a syncing request by calling
-[PSPDFInstantDocumentDescriptor stopSyncing:]
or cancellation as a result of trying to remove the annotation store from disk using-[PSPDFInstantDocumentDescriptor removeLocalStorageWithError:]
.
For more details on the sync cycle, please refer to the documentation ofPSPDFInstantDocumentState
.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient documentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor didFailSyncWithError:(nonnull NSError *)error;
Swift
optional func instantClient(_ instantClient: InstantClient, documentDescriptor: InstantDocumentDescriptor, didFailSyncWithError error: Error)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that failed synchronization.
error
The error that occurred.
-
Called when a sync cycle completes successfully.
A sync cycle finishes when there are no local changes left at the end of a sync operation.
For more details on the sync cycle, please refer to the documentation ofPSPDFInstantDocumentState
.Declaration
Objective-C
- (void)instantClient:(nonnull PSPDFInstantClient *)instantClient didFinishSyncForDocumentDescriptor: (nonnull id<PSPDFInstantDocumentDescriptor>)documentDescriptor;
Swift
optional func instantClient(_ instantClient: InstantClient, didFinishSyncFor documentDescriptor: InstantDocumentDescriptor)
Parameters
instantClient
The sender of the message.
documentDescriptor
The descriptor of the document that finished synchronization.