Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds instructions for how to use the Experimental Mac Catalyst Support #343

Merged
merged 9 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ The [PSPDFKit SDK](https://pspdfkit.com/) is a framework that allows you to view

#### Requirements

- Xcode 11
- PSPDFKit 9.0.0 for iOS or later
- react-native >= 0.60.5
- CocoaPods >= 1.7.5
- Xcode 11.3.1
- PSPDFKit 9.2.0 for iOS or later
- react-native >= 0.61.5
- CocoaPods >= 1.8.4

#### Getting Started

Expand Down Expand Up @@ -261,6 +261,14 @@ Example - Native UI Component:
- Run the app with `react-native-cli`: `react-native run-ios`
- If you get an error about `config.h` not being found check out [this blog post](https://tuntunir.blogspot.com/2018/02/react-native-fatal-error-configh-file.html) for information on how to fix it.

#### Running on Mac Catalyst

Using PSPDFKit React Native Wrapper on Mac Catalyst is not fully supported yet. We plan on adding full support for Mac Catalyst as soon as React Native and CocoaPods will full support Mac Catalyst.

For more details, see [why we don't fully support Mac Catalyst yet here](ios/Experimental_Mac_Catalyst_Support.md#why-is-mac-catalyst-not-fully-supported-yet).

If you wish to try the experimental Support for Mac Catalyst, please follow [the instructions here.](ios/Experimental_Mac_Catalyst_Support.md)

#### Configuration Mapping

The PSPDFKit React Native iOS Wrapper maps most configuration options available in `PSPDFConfiguration` from JSON. Please refer to [`RCTConvert+PSPDFConfiguration.m`](./ios/RCTPSPDFKit/Converters/RCTConvert+PSPDFConfiguration.m#L267) for the complete list and for the exact naming of enum values.
Expand Down
194 changes: 194 additions & 0 deletions ios/Experimental_Mac_Catalyst_Support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
## Experimental Mac Catalyst Support

## Why is Mac Catalyst Not Fully Supported Yet?

- Since React Native 0.60, [new React Native projects use CocoaPods by default](https://facebook.github.io/react-native/blog/2019/07/03/version-60#cocoapods-by-default).
- At the moment, the latest stable version of CocoaPods (1.8.4) does not support XCFrameworks, which are required for Mac Catalyst. Partial support for XCFrameworks has been added to CocoaPods version 1.9.0.beta.2. See https://github.com/CocoaPods/CocoaPods/issues/9148 for more details.
- React Native does not officially support Mac Catalyst. See https://github.com/react-native-community/discussions-and-proposals/issues/131
- In our CocoaPods artifacts, we do not offer XCFrameworks yet, but we plan on offering them as soon as they are fully supported by the latest stable version of CocoaPods.

Below, we walk you trough how to create your own local CocoaPods Artifacts that are compatible with XCFrameworks and Mac Catalyst. In this tutorial, we also discuss how to integrate PSPDFKit in a newly created React Native project and how to run it on a Mac.

**Note:** Since the instructions involve modifying React Native code to make the project compile on Mac Catalyst, the project will on run only on macOS and not on iOS.

### Requirements

- Xcode 11.3.1
- PSPDFKit 9.2.0 for iOS or later
- react-native >= 0.61.5
- CocoaPods >= 1.9.0.beta.2

### Getting Started

#### Creating the CocoaPods Artifacts

1. If you’re an existing customer, download PSPDFKit for iOS from the [customer portal](https://customers.pspdfkit.com/). Otherwise, if you don’t already have PSPDFKit, [sign up for our 60-day trial](https://pspdfkit.com/try/) and you will receive an email with the download instructions.
2. Copy `PSPDFKit.xcframework` and `PSPDFKitUI.xcframework` in a writable location.
3. Remove `strip-bitcode.sh` and `strip-framework.sh` from `PSPDFKit.xcframework/*/PSPDFKit.framework`:

```sh
rm PSPDFKit.xcframework/*/PSPDFKit.framework/strip-*.sh
```

4. Create an archive (`.zip` file) by compressing `PSPDFKit.xcframework` and `PSPDFKitUI.xcframework` into `PSPDFKit.zip`:
![compress-xcframeworks](../screenshots/compress-xcframeworks.png)
5. Rename the resulting `Archive.zip` to `PSPDFKit.zip`.

#### Integrating PSPDFKit in a New React Native Project

Let's create a simple app that integrates PSPDFKit and uses the `react-native-pspdfkit` module.

1. Make sure `react-native-cli` is installed: `yarn global add react-native-cli`
2. Create the app with `react-native init YourApp`.
3. Step into your newly created app folder: `cd YourApp`
4. Install `react-native-pspdfkit` from GitHub: `yarn add github:PSPDFKit/react-native`
5. Install all the dependencies for the project: `yarn install`. (Because of a [bug](https://github.com/yarnpkg/yarn/issues/2165) you may need to clean `yarn`'s cache with `yarn cache clean` before.)
6. Open `ios/Podile` in a text editor: `open ios/Podfile`, update the platform to iOS 11, and add the CocoaPods URLs:

```diff
- platform :ios, '9.0'
+ platform :ios, '11.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'YourApp' do
# Pods for YourApp
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'

pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

+ pod 'react-native-pspdfkit', :path => '../node_modules/react-native-pspdfkit'
+ pod 'PSPDFKit', podspec:'PSPDFKit.podspec'

use_native_modules!
end
```

7. In the `ios` folder, copy the CocoaPods artifatcs that you created earlier: `cp PSPDFKit.zip YourApp/ios/`.
8. In the `ios` folder, create a new `PSPDFKit.podspec` file with the following content:

```podspec
Pod::Spec.new do |s|
s.name = 'PSPDFKit'
s.version = '9.2.0'
s.homepage = 'https://pspdfkit.com'
s.documentation_url = 'https://pspdfkit.com/guides/ios/current'
s.license = { :type => 'Commercial', :file => 'PSPDFKit.xcframework/LICENSE' }
s.author = { 'PSPDFKit GmbH' => 'support@pspdfkit.com' }
s.summary = 'The leading cross-platform PDF framework.'

s.description = <<-DESC
The leading cross-platform PDF framework.
DESC
s.screenshots = 'https://pspdfkit.com/images/devices/ipad-air-hero-07c554d5.png'

s.platform = :ios, '11.0'
s.source = { :http => 'file:' + __dir__ + '/PSPDFKit.zip' }

s.library = 'z', 'sqlite3', 'xml2', 'c++'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/PSPDFKit/**"',
'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
s.frameworks = 'QuartzCore', 'CoreText', 'CoreMedia', 'MediaPlayer', 'AVFoundation', 'ImageIO', 'MessageUI',
'CoreGraphics', 'Foundation', 'CFNetwork', 'MobileCoreServices', 'SystemConfiguration',
'Security', 'UIKit', 'AudioToolbox', 'QuickLook', 'CoreTelephony',
'Accelerate', 'CoreImage'
s.requires_arc = true
s.swift_version = '5.0'
s.module_name = 'PSPDFKitSDK'

s.default_subspec = 'Core'

s.subspec 'Core' do |core|
core.preserve_paths = 'PSPDFKit.xcframework', 'PSPDFKitUI.xcframework'
core.public_header_files = 'PSPDFKit.xcframework/ios-arm64/PSPDFKit.framework/Headers/*.h', 'PSPDFKitUI.xcframework/ios-arm64/PSPDFKitUI.framework/Headers/*.h', 'PSPDFKit.xcframework/ios-x86_64-maccatalyst/PSPDFKit.framework/Headers/*.h', 'PSPDFKitUI.xcframework/ios-x86_64-maccatalyst/PSPDFKitUI.framework/Headers/*.h', 'PSPDFKit.xcframework/ios-x86_64-simulator/PSPDFKit.framework/Headers/*.h', 'PSPDFKitUI.xcframework/ios-x86_64-simulator/PSPDFKitUI.framework/Headers/*.h'
core.vendored_frameworks = 'PSPDFKit.xcframework', 'PSPDFKitUI.xcframework'
end
end
```

9. `cd ios` then run `pod install`.
10. Open `YourApp.xcworkspace` in Xcode: `open YourApp.xcworkspace`.
11. In Xcode in the Pods Xcode project > React-Core target > Build Phases > Compile Sources > RCTWebSocketModule.m change from `macOS + iOS`to `iOS` only
![fix-rctwebsocket-mac-catalyst](../screenshots/fix-rctwebsocket-mac-catalyst.png)
12. Edit your target's scheme and change the build configuration from `Debug` to `Release`. This is a hack to workaround the fact that there are some APIs that are not supported on Mac Catalyst that are ifdef'ed out in the release build configuration:
![edit-scheme](../screenshots/edit-scheme.png)
![set-release-build-configuration](../screenshots/set-release-build-configuration.png)
13. Allow your target to run on iPad and Mac:
![enable-mac](../screenshots/enable-mac.png)
14. Xcode will require you to select a development team in order to enable code signing and generate the right provisioning profiles.
15. 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:
![Adding PDF](../screenshots/adding-pdf.png)
16. Replace the default component from `App.js` with a simple touch area to present the bundled PDF. (Note that you can also use a [Native UI Component](../#native-ui-component) to show a PDF.)

```javascript
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
NativeModules,
Text,
TouchableHighlight,
View
} from "react-native";

const PSPDFKit = NativeModules.PSPDFKit;

PSPDFKit.setLicenseKey("INSERT_YOUR_LICENSE_KEY_HERE");

// Change 'YourApp' to your app's name.
export default class YourApp extends Component<Props> {
_onPressButton() {
PSPDFKit.present("document.pdf", {});
}

render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this._onPressButton}>
<Text style={styles.text}>Tap to Open Document</Text>
</TouchableHighlight>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
text: {
fontSize: 20,
textAlign: "center",
margin: 10
}
});

// Change both 'YourApp's to your app's name.
AppRegistry.registerComponent("YourApp", () => YourApp);
```

Your app is now ready to launch. Run the app in Xcode using `⌘+R`.
![launched-app-mac-catalyst](../screenshots/launched-app-mac-catalyst.png)
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.26.7",
"version": "1.26.8",
"description": "A React Native module for the PSPDFKit library.",
"keywords": [
"react native",
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.26.7",
"version": "1.26.8",
"private": true,
"scripts": {
"start": "react-native start",
Expand Down
2 changes: 1 addition & 1 deletion samples/NativeCatalog/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NativeCatalog",
"version": "1.26.7",
"version": "1.26.8",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
Binary file added screenshots/compress-xcframeworks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/edit-scheme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/enable-mac.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/fix-rctwebsocket-mac-catalyst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/launched-app-mac-catalyst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/set-release-build-configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.