@@ -105,18 +105,18 @@ - (UIViewController *)pspdf_parentViewController {
105105 return nil ;
106106}
107107
108- - (void )enterAnnotationCreationMode {
108+ - (BOOL )enterAnnotationCreationMode {
109109 [self .pdfController setViewMode: PSPDFViewModeDocument animated: YES ];
110110 [self .pdfController.annotationToolbarController updateHostView: nil container: nil viewController: self .pdfController];
111- [self .pdfController.annotationToolbarController showToolbarAnimated: YES ];
111+ return [self .pdfController.annotationToolbarController showToolbarAnimated: YES ];
112112}
113113
114- - (void )exitCurrentlyActiveMode {
115- [self .pdfController.annotationToolbarController hideToolbarAnimated: YES ];
114+ - (BOOL )exitCurrentlyActiveMode {
115+ return [self .pdfController.annotationToolbarController hideToolbarAnimated: YES ];
116116}
117117
118- - (void )saveCurrentDocument {
119- [self .pdfController.document saveWithOptions: nil error: NULL ];
118+ - (BOOL )saveCurrentDocument {
119+ return [self .pdfController.document saveWithOptions: nil error: NULL ];
120120}
121121
122122#pragma mark - PSPDFDocumentDelegate
@@ -178,15 +178,15 @@ - (void)flexibleToolbarContainerDidHide:(PSPDFFlexibleToolbarContainer *)contain
178178 return @{@" annotations" : annotationsJSON};
179179}
180180
181- - (void )addAnnotation : (id )jsonAnnotation {
181+ - (BOOL )addAnnotation : (id )jsonAnnotation {
182182 NSData *data;
183183 if ([jsonAnnotation isKindOfClass: NSString .class]) {
184184 data = [jsonAnnotation dataUsingEncoding: NSUTF8StringEncoding];
185185 } else if ([jsonAnnotation isKindOfClass: NSDictionary .class]) {
186186 data = [NSJSONSerialization dataWithJSONObject: jsonAnnotation options: 0 error: nil ];
187187 } else {
188188 NSLog (@" Invalid JSON Annotation." );
189- return ;
189+ return NO ;
190190 }
191191
192192 PSPDFDocument *document = self.pdfController .document ;
@@ -201,6 +201,40 @@ - (void)addAnnotation:(id)jsonAnnotation {
201201 if (!success) {
202202 NSLog (@" Failed to add annotation." );
203203 }
204+
205+ return success;
206+ }
207+
208+ - (BOOL )removeAnnotation : (id )jsonAnnotation {
209+ NSData *data;
210+ if ([jsonAnnotation isKindOfClass: NSString .class]) {
211+ data = [jsonAnnotation dataUsingEncoding: NSUTF8StringEncoding];
212+ } else if ([jsonAnnotation isKindOfClass: NSDictionary .class]) {
213+ data = [NSJSONSerialization dataWithJSONObject: jsonAnnotation options: 0 error: nil ];
214+ } else {
215+ NSLog (@" Invalid JSON Annotation." );
216+ return NO ;
217+ }
218+
219+ PSPDFDocument *document = self.pdfController .document ;
220+ PSPDFDocumentProvider *documentProvider = document.documentProviders .firstObject ;
221+
222+ BOOL success = NO ;
223+ if (data) {
224+ PSPDFAnnotation *annotationToRemove = [PSPDFAnnotation annotationFromInstantJSON: data documentProvider: documentProvider error: NULL ];
225+ for (PSPDFAnnotation *annotation in [document annotationsForPageAtIndex: annotationToRemove.pageIndex type: annotationToRemove.type]) {
226+ // Remove the annotation if the name matches.
227+ if ([annotation.name isEqualToString: annotationToRemove.name]) {
228+ success = [document removeAnnotations: @[annotation] options: nil ];
229+ break ;
230+ }
231+ }
232+ }
233+
234+ if (!success) {
235+ NSLog (@" Failed to remove annotation." );
236+ }
237+ return success;
204238}
205239
206240- (NSDictionary <NSString *, NSArray<NSDictionary *> *> *)getAllUnsavedAnnotations {
@@ -210,15 +244,15 @@ - (void)addAnnotation:(id)jsonAnnotation {
210244 return annotationsJSON;
211245}
212246
213- - (void )addAnnotations : (id )jsonAnnotations {
247+ - (BOOL )addAnnotations : (id )jsonAnnotations {
214248 NSData *data;
215249 if ([jsonAnnotations isKindOfClass: NSString .class]) {
216250 data = [jsonAnnotations dataUsingEncoding: NSUTF8StringEncoding];
217251 } else if ([jsonAnnotations isKindOfClass: NSDictionary .class]) {
218- data = [NSJSONSerialization dataWithJSONObject: jsonAnnotations options: 0 error: nil ];;
252+ data = [NSJSONSerialization dataWithJSONObject: jsonAnnotations options: 0 error: nil ];
219253 } else {
220254 NSLog (@" Invalid JSON Annotations." );
221- return ;
255+ return NO ;
222256 }
223257
224258 PSPDFDataContainerProvider *dataContainerProvider = [[PSPDFDataContainerProvider alloc ] initWithData: data];
@@ -228,6 +262,8 @@ - (void)addAnnotations:(id)jsonAnnotations {
228262 if (!success) {
229263 NSLog (@" Failed to add annotations." );
230264 }
265+
266+ return success;
231267}
232268
233269#pragma mark - Forms
0 commit comments