Skip to content

Commit 12fd061

Browse files
authored
Merge pull request #210 from PSPDFKit/rad/update-for-PSPDFKit-8.3-ios
Update for PSPDFKit 8.3 for iOS
2 parents 659f9da + a4fa849 commit 12fd061

File tree

7 files changed

+23
-30
lines changed

7 files changed

+23
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Let's create a simple app that integrates PSPDFKit and uses the `react-native-ps
4242
6. Link module `react-native-pspdfkit`: `react-native link react-native-pspdfkit`.
4343
7. Create the folder `ios/PSPDFKit` and copy `PSPDFKit.framework` and `PSPDFKitUI.framework` into it.
4444
8. Open `ios/YourApp.xcodeproj` in Xcode: `open ios/YourApp.xcodeproj`
45-
9. Make sure the deployment target is set to 10.0 or higher:
45+
9. Make sure the deployment target is set to 11.0 or higher:
4646
![Deployment Target](screenshots/deployment-target.png)
4747
10. Change "View controller-based status bar appearance" to `YES` in `Info.plist`:
4848
![View Controller-Based Status Bar Appearance](screenshots/view-controller-based-status-bar-appearance.png)

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import <React/RCTUtils.h>
1212
#import "RCTConvert+PSPDFAnnotation.h"
1313

14+
#define VALIDATE_DOCUMENT(document, ...) { if (!document.isValid) { NSLog(@"Document is invalid."); return __VA_ARGS__; }}
15+
1416
@interface RCTPSPDFKitView ()<PSPDFDocumentDelegate, PSPDFViewControllerDelegate, PSPDFFlexibleToolbarContainerDelegate>
1517

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

175177
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type {
176-
NSArray <PSPDFAnnotation *> *annotations = [self.pdfController.document annotationsForPageAtIndex:pageIndex type:type];
178+
PSPDFDocument *document = self.pdfController.document;
179+
VALIDATE_DOCUMENT(document, nil);
180+
181+
NSArray <PSPDFAnnotation *> *annotations = [document annotationsForPageAtIndex:pageIndex type:type];
177182
NSArray <NSDictionary *> *annotationsJSON = [RCTConvert instantJSONFromAnnotations:annotations];
178183
return @{@"annotations" : annotationsJSON};
179184
}
@@ -190,10 +195,7 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
190195
}
191196

192197
PSPDFDocument *document = self.pdfController.document;
193-
if (!document.isValid) {
194-
NSLog(@"Document is invalid.");
195-
return NO;
196-
}
198+
VALIDATE_DOCUMENT(document, NO)
197199
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
198200

199201
BOOL success = NO;
@@ -211,16 +213,12 @@ - (BOOL)addAnnotation:(id)jsonAnnotation {
211213

212214
- (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
213215
PSPDFDocument *document = self.pdfController.document;
214-
if (!document.isValid) {
215-
NSLog(@"Document is invalid.");
216-
return NO;
217-
}
218-
216+
VALIDATE_DOCUMENT(document, NO)
219217
BOOL success = NO;
220218

221219
NSArray<PSPDFAnnotation *> *allAnnotations = [[document allAnnotationsOfType:PSPDFAnnotationTypeAll].allValues valueForKeyPath:@"@unionOfArrays.self"];
222220
for (PSPDFAnnotation *annotation in allAnnotations) {
223-
// Remove the annotation if the name matches.
221+
// Remove the annotation if the uuids match.
224222
if ([annotation.uuid isEqualToString:annotationUUID]) {
225223
success = [document removeAnnotations:@[annotation] options:nil];
226224
break;
@@ -234,8 +232,11 @@ - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
234232
}
235233

236234
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAllUnsavedAnnotations {
237-
PSPDFDocumentProvider *documentProvider = self.pdfController.document.documentProviders.firstObject;
238-
NSData *data = [self.pdfController.document generateInstantJSONFromDocumentProvider:documentProvider error:NULL];
235+
PSPDFDocument *document = self.pdfController.document;
236+
VALIDATE_DOCUMENT(document, nil)
237+
238+
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
239+
NSData *data = [document generateInstantJSONFromDocumentProvider:documentProvider error:NULL];
239240
NSDictionary *annotationsJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL];
240241
return annotationsJSON;
241242
}
@@ -253,11 +254,7 @@ - (BOOL)addAnnotations:(id)jsonAnnotations {
253254

254255
PSPDFDataContainerProvider *dataContainerProvider = [[PSPDFDataContainerProvider alloc] initWithData:data];
255256
PSPDFDocument *document = self.pdfController.document;
256-
if (!document.isValid) {
257-
NSLog(@"Document is invalid.");
258-
return NO;
259-
}
260-
257+
VALIDATE_DOCUMENT(document, NO)
261258
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
262259
BOOL success = [document applyInstantJSONFromDataProvider:dataContainerProvider toDocumentProvider:documentProvider lenient:NO error:NULL];
263260
if (!success) {
@@ -277,10 +274,7 @@ - (BOOL)addAnnotations:(id)jsonAnnotations {
277274
}
278275

279276
PSPDFDocument *document = self.pdfController.document;
280-
if (!document.isValid) {
281-
NSLog(@"Document is invalid.");
282-
return nil;
283-
}
277+
VALIDATE_DOCUMENT(document, nil)
284278

285279
for (PSPDFFormElement *formElement in document.formParser.forms) {
286280
if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) {
@@ -299,10 +293,7 @@ - (void)setFormFieldValue:(NSString *)value fullyQualifiedName:(NSString *)fully
299293
}
300294

301295
PSPDFDocument *document = self.pdfController.document;
302-
if (!document.isValid) {
303-
NSLog(@"Document is invalid.");
304-
return;
305-
}
296+
VALIDATE_DOCUMENT(document)
306297

307298
for (PSPDFFormElement *formElement in document.formParser.forms) {
308299
if ([formElement.fullyQualifiedFieldName isEqualToString:fullyQualifiedName]) {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@
11261126
);
11271127
HEADER_SEARCH_PATHS = "";
11281128
INFOPLIST_FILE = Catalog/Info.plist;
1129+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
11291130
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11301131
OTHER_LDFLAGS = (
11311132
"$(inherited)",
@@ -1148,6 +1149,7 @@
11481149
);
11491150
HEADER_SEARCH_PATHS = "";
11501151
INFOPLIST_FILE = Catalog/Info.plist;
1152+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
11511153
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11521154
OTHER_LDFLAGS = (
11531155
"$(inherited)",

samples/Catalog/package.json

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

screenshots/deployment-target.png

387 KB
Loading

0 commit comments

Comments
 (0)