diff --git a/README.md b/README.md index 20f6b6bd..b07be544 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps 6. Link module `react-native-pspdfkit`: `react-native link react-native-pspdfkit`. 7. Create the folder `ios/PSPDFKit` and copy `PSPDFKit.framework` and `PSPDFKitUI.framework` into it. 8. Open `ios/YourApp.xcodeproj` in Xcode: `open ios/YourApp.xcodeproj` -9. Make sure the deployment target is set to 10.0 or higher: +9. Make sure the deployment target is set to 11.0 or higher: ![Deployment Target](screenshots/deployment-target.png) 10. Change "View controller-based status bar appearance" to `YES` in `Info.plist`: ![View Controller-Based Status Bar Appearance](screenshots/view-controller-based-status-bar-appearance.png) diff --git a/ios/RCTPSPDFKit/RCTPSPDFKitView.m b/ios/RCTPSPDFKit/RCTPSPDFKitView.m index 818fd273..3d8f4460 100644 --- a/ios/RCTPSPDFKit/RCTPSPDFKitView.m +++ b/ios/RCTPSPDFKit/RCTPSPDFKitView.m @@ -11,6 +11,8 @@ #import #import "RCTConvert+PSPDFAnnotation.h" +#define VALIDATE_DOCUMENT(document, ...) { if (!document.isValid) { NSLog(@"Document is invalid."); return __VA_ARGS__; }} + @interface RCTPSPDFKitView () @property (nonatomic, nullable) UIViewController *topController; @@ -173,7 +175,10 @@ - (void)flexibleToolbarContainerDidHide:(PSPDFFlexibleToolbarContainer *)contain #pragma mark - Instant JSON - (NSDictionary *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type { - NSArray *annotations = [self.pdfController.document annotationsForPageAtIndex:pageIndex type:type]; + PSPDFDocument *document = self.pdfController.document; + VALIDATE_DOCUMENT(document, nil); + + NSArray *annotations = [document annotationsForPageAtIndex:pageIndex type:type]; NSArray *annotationsJSON = [RCTConvert instantJSONFromAnnotations:annotations]; return @{@"annotations" : annotationsJSON}; } @@ -190,10 +195,7 @@ - (BOOL)addAnnotation:(id)jsonAnnotation { } PSPDFDocument *document = self.pdfController.document; - if (!document.isValid) { - NSLog(@"Document is invalid."); - return NO; - } + VALIDATE_DOCUMENT(document, NO) PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject; BOOL success = NO; @@ -211,16 +213,12 @@ - (BOOL)addAnnotation:(id)jsonAnnotation { - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID { PSPDFDocument *document = self.pdfController.document; - if (!document.isValid) { - NSLog(@"Document is invalid."); - return NO; - } - + VALIDATE_DOCUMENT(document, NO) BOOL success = NO; NSArray *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"]; for (PSPDFAnnotation *annotation in allAnnotations) { - // Remove the annotation if the name matches. + // Remove the annotation if the uuids match. if ([annotation.uuid isEqualToString:annotationUUID]) { success = [document removeAnnotations:@[annotation] options:nil]; break; @@ -234,8 +232,11 @@ - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID { } - (NSDictionary *> *)getAllUnsavedAnnotations { - PSPDFDocumentProvider *documentProvider = self.pdfController.document.documentProviders.firstObject; - NSData *data = [self.pdfController.document generateInstantJSONFromDocumentProvider:documentProvider error:NULL]; + PSPDFDocument *document = self.pdfController.document; + VALIDATE_DOCUMENT(document, nil) + + PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject; + NSData *data = [document generateInstantJSONFromDocumentProvider:documentProvider error:NULL]; NSDictionary *annotationsJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL]; return annotationsJSON; } @@ -253,11 +254,7 @@ - (BOOL)addAnnotations:(id)jsonAnnotations { PSPDFDataContainerProvider *dataContainerProvider = [[PSPDFDataContainerProvider alloc] initWithData:data]; PSPDFDocument *document = self.pdfController.document; - if (!document.isValid) { - NSLog(@"Document is invalid."); - return NO; - } - + VALIDATE_DOCUMENT(document, NO) PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject; BOOL success = [document applyInstantJSONFromDataProvider:dataContainerProvider toDocumentProvider:documentProvider lenient:NO error:NULL]; if (!success) { @@ -277,10 +274,7 @@ - (BOOL)addAnnotations:(id)jsonAnnotations { } PSPDFDocument *document = self.pdfController.document; - if (!document.isValid) { - NSLog(@"Document is invalid."); - return nil; - } + VALIDATE_DOCUMENT(document, nil) for (PSPDFFormElement *formElement in document.formParser.forms) { if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) { @@ -299,10 +293,7 @@ - (void)setFormFieldValue:(NSString *)value fullyQualifiedName:(NSString *)fully } PSPDFDocument *document = self.pdfController.document; - if (!document.isValid) { - NSLog(@"Document is invalid."); - return; - } + VALIDATE_DOCUMENT(document) for (PSPDFFormElement *formElement in document.formParser.forms) { if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) { diff --git a/package-lock.json b/package-lock.json index ea16940e..8cb5ff77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.7", + "version": "1.23.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 954b20c8..6ed7271e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.7", + "version": "1.23.8", "description": "A React Native module for the PSPDFKit library.", "keywords": [ "react native", diff --git a/samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj b/samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj index 6b13fa3e..d252f515 100644 --- a/samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj +++ b/samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj @@ -1126,6 +1126,7 @@ ); HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = Catalog/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( "$(inherited)", @@ -1148,6 +1149,7 @@ ); HEADER_SEARCH_PATHS = ""; INFOPLIST_FILE = Catalog/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( "$(inherited)", diff --git a/samples/Catalog/package.json b/samples/Catalog/package.json index fe1d66c2..0453b8c5 100644 --- a/samples/Catalog/package.json +++ b/samples/Catalog/package.json @@ -1,6 +1,6 @@ { "name": "Catalog", - "version": "1.23.7", + "version": "1.23.8", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start" diff --git a/screenshots/deployment-target.png b/screenshots/deployment-target.png index ac5caf1a..624c8349 100644 Binary files a/screenshots/deployment-target.png and b/screenshots/deployment-target.png differ