react-native-image-crop-picker: Cannot read property 'openPicker' of undefined

This project looks great and I’m really looking forward to using it. However I’m getting the error referenced in the title when trying to open the image picker in my app.

Here is the code:

import ImagePicker from 'react-native-image-crop-picker'

...

selectPhotoTapped() {
    console.log(ImagePicker)
    ImagePicker.openPicker({
      multiple: true
    }).then(images => {
      console.log(images);
    })
}

...

<TouchableOpacity onPress={this.selectPhotoTapped.bind(this)}>
  <View style={[styles.avatar, styles.avatarContainer, {marginBottom: 20}]}>
    { this.state.image === null ? <Text>Select a Photo</Text> :
      <Image style={styles.avatar} source={this.state.image} />
    }
  </View>
</TouchableOpacity>

And this is my Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'SclMktUi' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for SclMktUi

  target 'SclMktUiTests' do
    inherit! :search_paths
    source 'https://github.com/CocoaPods/Specs.git'
    pod 'React', :path => '../node_modules/react-native'
    pod 'react-native-image-crop-picker', :path => '../node_modules/react-native-image-crop-picker/ios'
    # Pods for testing
  end

end

Per the iOS install instructions I added $(inherited) to the Other Linker Flags field:

screen shot 2016-08-09 at 10 39 37 pm

When I run the code and click my TouchableOpacity I get the RSOD and the console log of ImagePicker reports undefined. Not sure what I’m doing wrong here.

From checking out [https://github.com/ivpusic/react-native-image-crop-picker/issues/33] I found that I had to undo the rnpm link at which point the build succeeded but I’m stuck at this undefined error. Everything looks good to my ignorant eyes 😄

Below is a screenshot of my Build Phases settings in Xcode. Any help would be greatly appreciated!

screen shot 2016-08-09 at 10 25 53 pm

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (5 by maintainers)

Most upvoted comments

You do some mistakes in your Podfile, move your pod import from the target SclMktUiTests to SclMktUi and try to change your platform :ios, '9.0' to platform :ios, '8.0'. Note the version of the platform in the Podfile need to be the same, as the version in Xcode!

So wen you do this small change your Podfile gonna looks like:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'

target 'SclMktUi' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for SclMktUi

  source 'https://github.com/CocoaPods/Specs.git'
  pod 'React', :path => '../node_modules/react-native'
  pod 'react-native-image-crop-picker', :path => '../node_modules/react-native-image-crop-picker/ios'

  target 'SclMktUiTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

After that do a pod install and try to rebuild your project 😃