If you don't have a Podfile in the ios folder of your React Native project, follow this guide to create one: https://facebook.github.io/react-native/docs/integration-with-existing-apps#configuring-cocoapods-dependencies
Add the following to your Podfile:
pod "react-native-heap", path: "../node_modules/@heap/react-native-heap"Then run:
pod installYou're done! 🎉
All terminal commands assume you are in the top-level directory of your React Native project.
- Locate the Xcode project for RNHeap:
open node_modules/@heap/react-native-heap/ios. You should see a Finder window containing theRNHeap.xcodeprojfile. - Open the Xcode project for your native app, in the
iosdirectory of your project. - Drag the
RNHeap.xcodeprojfile from the Finder window into the "Libraries" group of your Xcode project. - Select your project name in the Xcode project navigator. Select the "Build Phases" tab for your app's target.
- Expand the build phase called "Link Binary With Libraries". In the project navigator on the left, expand the
RNHeap.xcodeprojentry, and findlibRNHeap.ain the "Products" group. The icon forlibRNHeap.ashould look like a little building with columns. - Drag the
libRNHeap.afile into the list of other libraries to be linked. - Expand the build phase called "Copy Bundle Resources". In the project navigator on the left, expand the
RNHeap.xcodeprojentry, and findHeapSettings.bundle. Drag this into the list of bundle resources to be copied.
NOTE: Using react-native link is not currently supported
-
This library needs to be initialized so events are sent to the right application/environment ID. Place a
heap.config.jsonfile at the root of your application's repository with this structure, substituting your own application/environment IDs.{ "default": { "heapAutoInit": true }, "dev": { "heapAutoInit": true, "heapAppId": "11" }, "prod": { "heapAppId": "12", "heapAutoInit": true } } -
Note that different application/environment IDs can be set for development and production. Heap can also be enabled/disabled on a per-environment basis. Values in
defaultare used if a key is missing in eitherdevorprod. -
The library distinguishes between
devandprodbuilds using the__DEV__variable.
-
If you'd like finer-grained control over when the Heap library initializes, call
Heap.setAppIdwith an application/environment ID. (Most users won't need to do this.)import Heap from '@heap/react-native-heap'; Heap.setAppId('my-app-id');
-
Note that manual initialization on Android requires additional steps.
Build failures due to file not found errors
Build failures may occur if your Podfile does not specify the path to your local React pod, which should be added (and any other necessary subspecs) to your Podfile. You can find more information (and an example) in the official React Native docs. Failing to do so will result in the pod install step installing an additional React dependency (version 0.11 by default). You can confirm if correct React version is being used in Podfile.lock.
Linker error due to Undefined symbols for architecture x86_64:
This occurs at build time, and in its entirety, looks like this in the build log:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Heap", referenced from:
objc-class-ref in RNHeap.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This may appear if the Podfile contains a use_frameworks! directive. One solution is to add the following at the very end of your Podfile:
# Force react-native-heap to be built as a static framework.
# Based on comments at https://github.com/CocoaPods/CocoaPods/issues/7428 .
pre_install do |installer|
pod = installer.pod_targets.find { |p| p.name == 'react-native-heap'}
def pod.static_framework?
true
end
end