Skip to content

Latest commit

 

History

History
92 lines (64 loc) · 3.93 KB

INSTALL-IOS-COCOAPODS.md

File metadata and controls

92 lines (64 loc) · 3.93 KB

iOS Installation with CocoaPods

$ npm install --save react-native-background-geolocation

If you use already CocoaPods in your react-native project, you can also add the react-native-background-geolocation project to your Podfile.

NOTE The path to node_modules depends on your Podfile location, whether in {root} of the react-native project (node_modules) or {root}/ios (../node_modules). The following instructions assume {root}/ios

  • In your Podfile, make sure that platform :ios, '8.0' is set to 8.0
  • Add the following Pods (Including React if it's not already there)
platform :ios, '8.0'

#use_frameworks!  # <-- comment this out!
pod 'React', :path => '../node_modules/react-native'
pod 'RNBackgroundGeolocation', :path => '../node_modules/react-native-background-geolocation'
pod 'RNBackgroundFetch', :path => '../node_modules/react-native-background-fetch'
  • Install the new CocoaPods dependency with:
$ pod install

XCode Configuration

  • Open your App.xcworkspace

Configure Background Capabilities

  • Select the root of your project. Select Capabilities tab. Enable Background Modes and enable the following modes:

  • Location updates

  • Background fetch

  • Audio (optional for debug-mode sound FX)

  • Edit Info.plist. Add the following items (Set Value as desired):
Key Value Description
NSLocationAlwaysUsageDescription This app requires background tracking The value here will be presented to the user when the plugin requests Background Location permission
NSMotionUsageDescription Accelerometer use increases battery efficiency by intelligently toggling location-tracking The value here will be presented to the user when the app requests Motion Activity permission.

BackgroundFetch AppDelegate extension

BackgroundFetch implements an AppDelegate method didPerformFetchWithCompletionHandler. You must manually add this file to the same folder where your AppDelegate.m lives:

  • Right click your app's root folder. Select Add files to.... Select Other.

  • Browse to {YourApp}/node_modules/react-native-background-fetch/ios/RNBackgroundFetch.

  • Add the file RNBackgroundFetch+AppDelegate.m:

Troubleshooting with CocoaPods

Because react-native is only available as npm module (and not as "regular" CocoaPods dependency, see v0.13 release notes for more informations).

So it is required that you import react-native also from a local path. Ensure that you include React before you include react-native-background-fetch in your Podfile. Here is a complete working example if you want add your Podfile in the project root while your generated Xcode project is still in the ios folder:

Newer versions of react-native might give you error of a missing Yoga dependency.

Unable to satisfy the following requirements:

- `Yoga (= 0.44.0.React)` required by `React/Core (0.44.0)`

None of your spec sources contain a spec satisfying the dependency: `Yoga (= 0.44.0.React)`.

To solve this, just include the path to the Yoga pod.

platform :ios, '8.0'
# pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga' <-- uncomment to solve Yoga error
pod 'React', :path => '../node_modules/react-native'
pod 'RNBackgroundGeolocation', :path => '../node_modules/react-native-background-geolocation'
pod 'RNBackgroundFetch', :path => '../node_modules/react-native-background-fetch'