Skip to content

Commit

Permalink
Merge pull request #210 from PSPDFKit/rad/update-for-PSPDFKit-8.3-ios
Browse files Browse the repository at this point in the history
Update for PSPDFKit 8.3 for iOS
  • Loading branch information
radazzouz authored Apr 23, 2019
2 parents 659f9da + a4fa849 commit 12fd061
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 17 additions & 26 deletions ios/RCTPSPDFKit/RCTPSPDFKitView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import <React/RCTUtils.h>
#import "RCTConvert+PSPDFAnnotation.h"

#define VALIDATE_DOCUMENT(document, ...) { if (!document.isValid) { NSLog(@"Document is invalid."); return __VA_ARGS__; }}

@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate, PSPDFFlexibleToolbarContainerDelegate>

@property (nonatomic, nullable) UIViewController *topController;
Expand Down Expand Up @@ -173,7 +175,10 @@ - (void)flexibleToolbarContainerDidHide:(PSPDFFlexibleToolbarContainer *)contain
#pragma mark - Instant JSON

- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type {
NSArray <PSPDFAnnotation *> *annotations = [self.pdfController.document annotationsForPageAtIndex:pageIndex type:type];
PSPDFDocument *document = self.pdfController.document;
VALIDATE_DOCUMENT(document, nil);

NSArray <PSPDFAnnotation *> *annotations = [document annotationsForPageAtIndex:pageIndex type:type];
NSArray <NSDictionary *> *annotationsJSON = [RCTConvert instantJSONFromAnnotations:annotations];
return @{@"annotations" : annotationsJSON};
}
Expand All @@ -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;
Expand All @@ -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<PSPDFAnnotation *> *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;
Expand All @@ -234,8 +232,11 @@ - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
}

- (NSDictionary<NSString *, NSArray<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;
}
Expand All @@ -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) {
Expand All @@ -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]) {
Expand All @@ -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]) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions samples/Catalog/ios/Catalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion samples/Catalog/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Binary file modified screenshots/deployment-target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 12fd061

Please sign in to comment.