Skip to content

Commit e7d7399

Browse files
authored
Merge pull request #18 from PSPDFKit/rad/podspec
Added podspec for CocoaPods integration
2 parents ef4a78c + e706f3e commit e7d7399

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

ios/cocoapods.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
## PSPDFKit for React Native
2+
3+
### CocoaPods integration
4+
5+
#### Requirements
6+
- Xcode 8.3.3
7+
- PSPDFKit >=6.8
8+
- react-native >= 0.46.4
9+
- CocoaPods >= 1.2.1
10+
11+
#### Getting Started
12+
13+
Lets create a simple app that integrates `PSPDFKit.framework` using CocoaPods.
14+
15+
1. Make sure `react-native-cli` is installed: `yarn global add react-native-cli`
16+
2. Create the app with `react-native init YourApp`.
17+
3. Step into your newly created app folder: `cd YourApp`
18+
4. Install `react-native-pspdfkit` from GitHub: `yarn add github:PSPDFKit/react-native`
19+
5. IMPORTANT: Do not link module react-native-pspdfkit: Do not use react-native link react-native-pspdfkit
20+
6. Create the folder `ios/PSPDFKit` and copy `PSPDFKit.framework` into it.
21+
7. Open ios/YourApp.xcodeproj in Xcode: open ios/YourApp.xcodeproj
22+
8. Make sure the deployment target is set to 9.0 or higher:
23+
![Deployment Target](../screenshots/deployment-target.png)
24+
9. Change "View controller-based status bar appearance" to YES in Info.plist:
25+
deployment-target.png
26+
10. Close the Xcode project
27+
11. Go back to the Terminal, `cd ios` then run `pod init`
28+
12. Replace the content of your newly created `Podfile` with this:
29+
30+
```podfile
31+
target 'YourApp' do
32+
use_frameworks!
33+
34+
pod 'react-native-pspdfkit', :path => '../node_modules/react-native-pspdfkit'
35+
36+
# To use CocoaPods with React Native, you need to add this specific Yoga spec as well
37+
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga/Yoga.podspec'
38+
39+
# You don't necessarily need all of these subspecs, but this would be a typical setup.
40+
pod 'React', :path => '../node_modules/react-native', :subspecs => [
41+
'Core',
42+
'RCTText',
43+
'RCTNetwork',
44+
'RCTWebSocket', # needed for debugging
45+
'RCTAnimation',
46+
'RCTImage',
47+
'RCTNetwork',
48+
'BatchedBridge', # https://github.com/facebook/react-native/issues/14749
49+
# Add any other subspecs you want to use in your project
50+
]
51+
52+
# Add any other dependencies here, including any 3rd party native libraries that you depend on for
53+
# React Native.
54+
end
55+
```
56+
57+
13. Run `pod install`
58+
14. Open the newly created workspace: `YourApp.workspace`
59+
15. Copy `PSPDFKit.framework` into the Pods folder: `YourApp/ios/Pods`
60+
16. Drag and drop it from the Finder into the `RCTPSPDFKit` group:
61+
![Deployment Target](../screenshots/embedding-pspdfkit-pods.png)
62+
17. Add it to the `react-native-pspdfkit` framework:
63+
![Deployment Target](../screenshots/adding-to-react-native-pspdfkit.png)
64+
18. Embed `YourApp/ios/PSPDFKit/PSPDFKit.framework` (not the copy from `YourApp/ios/Pods/PSPDFKit.framework`) by drag and dropping it into the "Embedded Binaries" section of the "YourApp" target (Select "Create groups"). This will also add it to the "Linked Frameworks and Libraries" section:
65+
![Embedding PSPDFKit](../screenshots/embedding-pspdfkit.png)
66+
19. Add a PDF by drag and dropping it into your Xcode project (Select "Create groups" and add to target "YourApp"). This will add the document to the "Copy Bundle Resources" build phase:
67+
![Adding PDF](../screenshots/adding-pdf.png)
68+
20. Replace the default component from `index.ios.js` with a simple touch area to present the bundled PDF:
69+
70+
```javascript
71+
import React, { Component } from 'react';
72+
import {
73+
AppRegistry,
74+
StyleSheet,
75+
NativeModules,
76+
Text,
77+
TouchableHighlight,
78+
View
79+
} from 'react-native';
80+
81+
var PSPDFKit = NativeModules.PSPDFKit;
82+
83+
PSPDFKit.setLicenseKey('INSERT_YOUR_LICENSE_KEY_HERE');
84+
85+
// Change 'YourApp' to your app's name.
86+
class YourApp extends Component {
87+
_onPressButton() {
88+
PSPDFKit.present('document.pdf', {})
89+
}
90+
91+
render() {
92+
return (
93+
<View style={styles.container}>
94+
<TouchableHighlight onPress={this._onPressButton}>
95+
<Text style={styles.text}>Tap to Open Document</Text>
96+
</TouchableHighlight>
97+
</View>
98+
);
99+
}
100+
}
101+
102+
const styles = StyleSheet.create({
103+
container: {
104+
flex: 1,
105+
justifyContent: 'center',
106+
alignItems: 'center',
107+
backgroundColor: '#F5FCFF',
108+
},
109+
text: {
110+
fontSize: 20,
111+
textAlign: 'center',
112+
margin: 10,
113+
}
114+
});
115+
116+
// Change both 'YourApp's to your app's name.
117+
AppRegistry.registerComponent('YourApp', () => YourApp);
118+
```
119+
120+
Your app is now ready to launch. Run the app in Xcode or type `react-native run-ios` in the terminal.

react-native-pspdfkit.podspec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |s|
6+
s.name = "react-native-pspdfkit"
7+
s.version = package['version']
8+
s.summary = "A React Native module for the PSPDFKit library."
9+
s.authors = ["PSPDFKit"]
10+
s.homepage = "https://github.com/PSPDFKit/react-native#readme"
11+
s.license = package['license']
12+
s.platform = :ios, "9.0"
13+
s.module_name = 'PSPDFKitReactNativeiOS'
14+
s.source = { :git => "https://github.com/PSPDFKit/react-native" }
15+
s.source_files = "ios/*.{xcodeproj}", "ios/RCTPSPDFKit/*.{h,m,swift}", "ios/RCTPSPDFKit/Converters/*.{h,m,swift}"
16+
s.dependency 'React'
17+
s.frameworks = 'UIKit'
18+
end
83.4 KB
Loading
99.4 KB
Loading

0 commit comments

Comments
 (0)