【问题标题】:Expo ImagePicker crashed on IOS Gallery not openingExpo ImagePicker 在 IOS Gallery 上崩溃,无法打开
【发布时间】:2019-11-05 02:05:21
【问题描述】:

当我尝试使用 expo imagepicker 时,应用程序冻结,打开图库或相机并立即关闭,这仅在 ios 上发生在我身上,在 android 上它可以完美运行。

我希望有人可以帮助我。

这是我的代码

  getPermissionAsync = async () => {
    if (Constants.platform.ios) {
      const { status } = await Permissions.askAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL);
      if (status !== "granted") {
        alert(
          "Lo sentimos, necesitamos permisos de cámara para hacer que esto funcione!"
        );
      }
    }
  };

  _pickImage = async type => {
    let result = null;
    if (type == "galeria") {
      result = await ImagePicker.launchImageLibraryAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.Images,
        quality: 0.5,
        base64: true
      });
    } else {
      result = await ImagePicker.launchCameraAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.Images,
        quality: 0.5,
        base64: true
      });
    }

    if (result != null && !result.cancelled) {
      let arr = this.state.imagenesAdjuntas;
      arr.push(result);
      this.setState({ imagenesAdjuntas: arr });
    }
  };

这些是依赖项

"dependencies": {
    "@expo/vector-icons": "^10.0.3",
    "expo": "^33.0.0",
    "expo-asset": "^6.0.0",
    "expo-barcode-scanner": "~5.0.1",
    "expo-blur": "~5.0.1",
    "expo-constants": "~5.0.1",
    "expo-font": "~5.0.1",
    "expo-image-picker": "~5.0.2",
    "expo-linear-gradient": "^5.0.1",
    "expo-mail-composer": "~5.0.1",
    "expo-permissions": "~5.0.1",
    "expo-secure-store": "~5.0.1",
    "firebase": "^7.2.1",
    "prop-types": "^15.7.2",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
    "react-native-animated-hide-view": "^1.0.0",
    "react-native-banner-carousel": "^1.0.3",
    "react-native-elements": "^1.2.6",
    "react-native-flip-card": "^3.5.5",
    "react-native-gesture-handler": "~1.2.1",
    "react-native-maps": "~0.24.0",
    "react-native-modal": "^11.1.0",
    "react-native-render-html": "^4.1.2",
    "react-native-smtp-mailer": "^1.2.1",
    "react-native-table-component": "^1.2.0",
    "react-native-web": "^0.11.4",
    "react-navigation": "^3.11.0",
    "sharp": "^0.22.1"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.1.1"
  },

这是 app.json

{
  "expo": {
    "name": "App Name",
    "slug": "appname",
    "privacy": "public",
    "sdkVersion": "33.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "loading": {
      "icon": "./assets/icon.png",
      "hideExponentText": false
    },
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "cover",
      "backgroundColor": "#0088AD"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "packagerOpts": {
      "assetExts": [
        "ttf",
        "mp4",
        "otf",
        "xml",
        "html",
        "js"
      ]
    },
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.company.name"
    },
    "android": {
      "package": "com.company.name",
      "config": {
      }
    },
    "description": ""
  }
}

下面我会填

Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作一本类型样本书。它不仅经历了五个世纪,而且经历了电子排版的飞跃,基本保持不变。它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行起来,最近又随着 Aldus PageMaker 等桌面出版软件(包括 Lorem Ipsum 的版本)而普及。

【问题讨论】:

标签: ios react-native expo imagepicker


【解决方案1】:

您应该在 xcode 内的项目 plist 文件中添加此权限。 在文件中添加这两个条目

NSCameraUsageDescription



NSPhotoLibraryUsageDescription

对你有帮助,对我有帮助

【讨论】:

    【解决方案2】:

    尝试将它添加到您的对象中,像这样,

    ImagePicker.launchImageLibraryAsync({
         mediaTypes: ImagePicker.MediaTypeOptions.Images,
         quality: 0.5,
         base64: true
         presentationStyle: 0 //add this
    });
    

    有了这个,一切都应该在 IOS 上完美运行

    【讨论】:

    • 这为我解决了问题。
    • 我相信这是一个真正的突破
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 2019-03-03
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多