Skip to content

Commit 4e80b15

Browse files
authored
Merge pull request #209 from PSPDFKit/rad/document-validation-check
Check if document is valid before adding or removing annotations
2 parents 6215cea + 1028a80 commit 4e80b15

File tree

9 files changed

+79
-18
lines changed

9 files changed

+79
-18
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ The [PSPDFKit SDK](https://pspdfkit.com/) is a framework that allows you to view
2424

2525
#### Requirements
2626

27-
- Xcode 10.1
28-
- PSPDFKit 8.1.3 for iOS or later
27+
- Xcode 10.2
28+
- PSPDFKit 8.2.3 for iOS or later
2929
- react-native >= 0.57.8
3030

3131
#### Getting Started

ios/RCTPSPDFKit.xcodeproj/project.pbxproj

+18-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
83CBB9F71A601CBA00E9B192 /* Project object */ = {
131131
isa = PBXProject;
132132
attributes = {
133-
LastUpgradeCheck = 0800;
133+
LastUpgradeCheck = 1020;
134134
ORGANIZATIONNAME = Facebook;
135135
TargetAttributes = {
136136
657277141D8312EA00A5E1A8 = {
@@ -144,6 +144,7 @@
144144
developmentRegion = English;
145145
hasScannedForEncodings = 0;
146146
knownRegions = (
147+
English,
147148
en,
148149
Base,
149150
);
@@ -210,14 +211,22 @@
210211
CLANG_CXX_LIBRARY = "libc++";
211212
CLANG_ENABLE_MODULES = YES;
212213
CLANG_ENABLE_OBJC_ARC = YES;
214+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
213215
CLANG_WARN_BOOL_CONVERSION = YES;
216+
CLANG_WARN_COMMA = YES;
214217
CLANG_WARN_CONSTANT_CONVERSION = YES;
218+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
215219
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
216220
CLANG_WARN_EMPTY_BODY = YES;
217221
CLANG_WARN_ENUM_CONVERSION = YES;
218222
CLANG_WARN_INFINITE_RECURSION = YES;
219223
CLANG_WARN_INT_CONVERSION = YES;
224+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
225+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
226+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
220227
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
228+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
229+
CLANG_WARN_STRICT_PROTOTYPES = YES;
221230
CLANG_WARN_SUSPICIOUS_MOVE = YES;
222231
CLANG_WARN_UNREACHABLE_CODE = YES;
223232
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -266,14 +275,22 @@
266275
CLANG_CXX_LIBRARY = "libc++";
267276
CLANG_ENABLE_MODULES = YES;
268277
CLANG_ENABLE_OBJC_ARC = YES;
278+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
269279
CLANG_WARN_BOOL_CONVERSION = YES;
280+
CLANG_WARN_COMMA = YES;
270281
CLANG_WARN_CONSTANT_CONVERSION = YES;
282+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
271283
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
272284
CLANG_WARN_EMPTY_BODY = YES;
273285
CLANG_WARN_ENUM_CONVERSION = YES;
274286
CLANG_WARN_INFINITE_RECURSION = YES;
275287
CLANG_WARN_INT_CONVERSION = YES;
288+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
289+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
290+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
276291
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
292+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
293+
CLANG_WARN_STRICT_PROTOTYPES = YES;
277294
CLANG_WARN_SUSPICIOUS_MOVE = YES;
278295
CLANG_WARN_UNREACHABLE_CODE = YES;
279296
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

ios/RCTPSPDFKit/RCTPSPDFKitView.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@import PSPDFKit;
1414
@import PSPDFKitUI;
1515

16+
NS_ASSUME_NONNULL_BEGIN
17+
1618
@interface RCTPSPDFKitView: UIView
1719

1820
@property (nonatomic, readonly) PSPDFViewController *pdfController;
@@ -47,3 +49,5 @@
4749
- (void)setFormFieldValue:(NSString *)value fullyQualifiedName:(NSString *)fullyQualifiedName;
4850

4951
@end
52+
53+
NS_ASSUME_NONNULL_END

ios/RCTPSPDFKit/RCTPSPDFKitView.m

+33-9
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
190190
}
191191

192192
PSPDFDocument *document = self.pdfController.document;
193+
if (!document.isValid) {
194+
NSLog(@"Document is invalid.");
195+
return NO;
196+
}
193197
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
194198

195199
BOOL success = NO;
@@ -207,18 +211,22 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
207211

208212
- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
209213
PSPDFDocument *document = self.pdfController.document;
210-
214+
if (!document.isValid) {
215+
NSLog(@"Document is invalid.");
216+
return NO;
217+
}
218+
211219
BOOL success = NO;
212220

213221
NSArray<PSPDFAnnotation *> *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"];
214-
for (PSPDFAnnotation *annotation in allAnnotations) {
215-
// Remove the annotation if the name matches.
216-
if ([annotation.uuid isEqualToString:annotationUUID]) {
217-
success = [document removeAnnotations:@[annotation] options:nil];
218-
break;
219-
}
222+
for (PSPDFAnnotation *annotation in allAnnotations) {
223+
// Remove the annotation if the name matches.
224+
if ([annotation.uuid isEqualToString:annotationUUID]) {
225+
success = [document removeAnnotations:@[annotation] options:nil];
226+
break;
220227
}
221-
228+
}
229+
222230
if (!success) {
223231
NSLog(@"Failed to remove annotation.");
224232
}
@@ -245,12 +253,18 @@ - (BOOL)addAnnotations:(id)jsonAnnotations {
245253

246254
PSPDFDataContainerProvider *dataContainerProvider = [[PSPDFDataContainerProvider alloc] initWithData:data];
247255
PSPDFDocument *document = self.pdfController.document;
256+
if (!document.isValid) {
257+
NSLog(@"Document is invalid.");
258+
return NO;
259+
}
260+
248261
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
249-
BOOL success = [document applyInstantJSONFromDataProvider:dataContainerProvider toDocumentProvider:documentProvider error:NULL];
262+
BOOL success = [document applyInstantJSONFromDataProvider:dataContainerProvider toDocumentProvider:documentProvider lenient:NO error:NULL];
250263
if (!success) {
251264
NSLog(@"Failed to add annotations.");
252265
}
253266

267+
[self.pdfController reloadPageAtIndex:self.pdfController.pageIndex animated:NO];
254268
return success;
255269
}
256270

@@ -263,6 +277,11 @@ - (BOOL)addAnnotations:(id)jsonAnnotations {
263277
}
264278

265279
PSPDFDocument *document = self.pdfController.document;
280+
if (!document.isValid) {
281+
NSLog(@"Document is invalid.");
282+
return nil;
283+
}
284+
266285
for (PSPDFFormElement *formElement in document.formParser.forms) {
267286
if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) {
268287
id formFieldValue = formElement.value;
@@ -280,6 +299,11 @@ - (void)setFormFieldValue:(NSString *)value fullyQualifiedName:(NSString *)fully
280299
}
281300

282301
PSPDFDocument *document = self.pdfController.document;
302+
if (!document.isValid) {
303+
NSLog(@"Document is invalid.");
304+
return;
305+
}
306+
283307
for (PSPDFFormElement *formElement in document.formParser.forms) {
284308
if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) {
285309
if ([formElement isKindOfClass:PSPDFButtonFormElement.class]) {

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-pspdfkit",
3-
"version": "1.23.5",
3+
"version": "1.23.6",
44
"description": "A React Native module for the PSPDFKit library.",
55
"keywords": [
66
"react native",

samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj

+18-2
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
isa = PBXProject;
656656
attributes = {
657657
CLASSPREFIX = RCTPSPDF;
658-
LastUpgradeCheck = 0800;
658+
LastUpgradeCheck = 1020;
659659
ORGANIZATIONNAME = "PSPDFKit GmbH";
660660
TargetAttributes = {
661661
00E356ED1AD99517003FC87E = {
@@ -666,7 +666,7 @@
666666
};
667667
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "Catalog" */;
668668
compatibilityVersion = "Xcode 3.2";
669-
developmentRegion = English;
669+
developmentRegion = en;
670670
hasScannedForEncodings = 0;
671671
knownRegions = (
672672
en,
@@ -1168,14 +1168,22 @@
11681168
CLANG_CXX_LIBRARY = "libc++";
11691169
CLANG_ENABLE_MODULES = YES;
11701170
CLANG_ENABLE_OBJC_ARC = YES;
1171+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
11711172
CLANG_WARN_BOOL_CONVERSION = YES;
1173+
CLANG_WARN_COMMA = YES;
11721174
CLANG_WARN_CONSTANT_CONVERSION = YES;
1175+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
11731176
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
11741177
CLANG_WARN_EMPTY_BODY = YES;
11751178
CLANG_WARN_ENUM_CONVERSION = YES;
11761179
CLANG_WARN_INFINITE_RECURSION = YES;
11771180
CLANG_WARN_INT_CONVERSION = YES;
1181+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
1182+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
1183+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
11781184
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1185+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1186+
CLANG_WARN_STRICT_PROTOTYPES = YES;
11791187
CLANG_WARN_SUSPICIOUS_MOVE = YES;
11801188
CLANG_WARN_UNREACHABLE_CODE = YES;
11811189
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -1218,14 +1226,22 @@
12181226
CLANG_CXX_LIBRARY = "libc++";
12191227
CLANG_ENABLE_MODULES = YES;
12201228
CLANG_ENABLE_OBJC_ARC = YES;
1229+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
12211230
CLANG_WARN_BOOL_CONVERSION = YES;
1231+
CLANG_WARN_COMMA = YES;
12221232
CLANG_WARN_CONSTANT_CONVERSION = YES;
1233+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
12231234
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
12241235
CLANG_WARN_EMPTY_BODY = YES;
12251236
CLANG_WARN_ENUM_CONVERSION = YES;
12261237
CLANG_WARN_INFINITE_RECURSION = YES;
12271238
CLANG_WARN_INT_CONVERSION = YES;
1239+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
1240+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
1241+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
12281242
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1243+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1244+
CLANG_WARN_STRICT_PROTOTYPES = YES;
12291245
CLANG_WARN_SUSPICIOUS_MOVE = YES;
12301246
CLANG_WARN_UNREACHABLE_CODE = YES;
12311247
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

samples/Catalog/ios/Catalog.xcodeproj/xcshareddata/xcschemes/Catalog.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "NO"

samples/Catalog/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Catalog",
3-
"version": "1.23.5",
3+
"version": "1.23.6",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start"

0 commit comments

Comments
 (0)