-1

アプリに react-native-image-picker があります。ImagePicker.launchImageLibrary を呼び出している場合、アプリはギャラリーを開く代わりに閉じています。そして、ImagePicker.showImagePicker を呼び出して、Choose from library.. オプションを呼び出すと、同じ動作が発生します。アプリも閉じます。公式ドキュメントと同じコードを使用し、XCode、接続されたライブラリ、Pod ですべてのインストールを行いましたが、エラーはありませんでした。誰か助けてください。

import React, { useState } from 'react'
import { View, FlatList, StyleSheet } from 'react-native'
import ImagePicker from 'react-native-image-picker'
import { ChannelItem, ModalChannelCard, SearchBar, ScreenHeader } from '../../components'
import { data } from '../../dataDraft'
import { TOPICS_SCREEN } from '../routes'

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  textStyle: {
    fontSize: 25,
    fontWeight: 'bold'
  }
})

const ChannelsScreen = ({ navigation }) => {
  const { container, textStyle } = styles
  const [isModalVisible, setModalVisible] = useState(false)
  const [newChannelImage, setNewChannelImage] = useState({
    channelImage: null,
    loading: false
  })
  const [newChannelTitle, setNewChannelTitle] = useState('')
  const [userInput, setInput] = useState({
    value: '',
    isEmpty: true
  })
  const onChangeTexthandler = value => {
    setInput({
      value,
      isEmpty: false
    })
  }
  const onPressXButtonHandler = () => {
    setInput({
      value: '',
      isEmpty: true
    })
  }
  const hideModalHandler = () => {
    setModalVisible(false)
  }
  const setChannelImageHandler = ({ source }) => {
    setNewChannelImage({
      channelImage: source,
      loading: true
    })
  }
  const rightIconPressHandler = () => {
    setModalVisible(true)
  }
  const chooseChannelImageHandler = () => {
    const options = {
      title: 'Select Image',
      storageOptions: {
        skipBackup: true,
        path: 'images'
      }
    }
    ImagePicker.showImagePicker(options, response => {
      console.log('Response = ', response)
      if (response.didCancel) {
        console.log('User cancelled image picker')
      } else if (response.error) {
        console.log('ImagePicker error: ', response.error)
      } else if (response.customButton) {
        console.log('User tapped custom button: ', response.customButton)
        alert(response.customButton)
      } else {
        const source = { uri: response.uri }
        setChannelImageHandler(source.uri)
      }
    })
  }

  const newTitleHandler = value => {
    setNewChannelTitle(value)
  }
  return (
    <View style={container}>
      <ScreenHeader header="Channels" rightIconName="ios-add" onRightIconPress={rightIconPressHandler} />
      <SearchBar
        value={userInput.value}
        placeholder="Search channel..."
        isEmpty={userInput.isEmpty}
        onChangeText={onChangeTexthandler}
        onPressXButton={onPressXButtonHandler}
      />
      <ModalChannelCard
        buttonAddChannelPushed={newChannelImage.loading}
        channelImage={newChannelImage.channelImage}
        chooseChannelImage={chooseChannelImageHandler}
        createChannel={hideModalHandler}
        hideModal={hideModalHandler}
        onChangeTitle={newTitleHandler}
        titleValue={newChannelTitle}
        visible={isModalVisible}
      />

      <View style={{ alignItems: 'center' }}>
        <FlatList
          data={data}
          numColumns={2}
          autoCorrect={false}
          keyboardShouldPersistTaps="always"
          keyboardDismissMode="on-drag"
          keyExtractor={item => item.image}
          renderItem={({ item }) => (
            <ChannelItem
              channelItemHeader={item.header}
              imageSource={item.image}
              onPress={() => navigation.navigate(TOPICS_SCREEN)}
            />
          )}
        />
      </View>
    </View>
  )
}

export default ChannelsScreen

4

1 に答える 1

0

私は解決策を見つけました。この手順を完了していません: 注: この手順を完了していないと、SIGABRT がクラッシュします。

<plist version="1.0">
  <dict>
    ...
    <key>NSPhotoLibraryUsageDescription</key>
    <string>$(PRODUCT_NAME) would like access to your photo gallery</string>
    <key>NSCameraUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your camera</string>
    <key>NSPhotoLibraryAddUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>$(PRODUCT_NAME) would like to use your microphone (for videos)</string>
  </dict>
</plist>
于 2019-07-22T08:51:22.603 に答える