Я построил приложение, используя Expo Managed Workflow, и я развернул его в App Store. Однако он сбои (только на iOS, на Android, он работает нормально), только если вы выберете изображение из альбома (если вы выбираете его непосредственно из своей галереи, все в порядке). Я не понимаю, почему это происходит, из того, что я понимаю, URI отличается между этими двумя сценариями, но я не знаю, как его решить, поэтому любая помощь будет очень ценить это !! < /p>
import React, { useState, useEffect } from "react";
import { View, Alert, Text } from "react-native";
import { useNavigation, useRoute } from "@react-navigation/native";
import * as ImagePicker from "expo-image-picker";
import BusinessCard from "../../components/BusinessCard";
import { getDownloadURL, ref, uploadBytes } from "firebase/storage";
import { addUserToBusiness } from "../../utils/UsersUtils/UsersUtils";
import uuid from "react-native-uuid";
import { addBusiness } from "../../utils/BusinessUtils/BusinessUtils";
import { useUser } from "../../utils/Context/UserContext";
import { storage } from "../../../Firebase/firebase";
import CustomButton from "../../components/CustomButton";
import { themeColors } from "../../theme";
import { styles } from "../../styles/styles";
import { useTranslation } from "react-i18next";
import { useAllPermissions } from "../../utils/PermissionsUtils/PermissionsUtils";
import { useStripe } from "@stripe/stripe-react-native"; // Stripe SDK
import { addSubscription } from "../../utils/StripeUtils/StripeUtils";
import { ScaledSheet } from "react-native-size-matters";
const LogoScreen = () => {
const { t } = useTranslation();
const { loading3, permissions: fetchedPermissions } = useAllPermissions();
const route = useRoute();
const navigation = useNavigation();
const { user: userData, loading } = useUser();
const lastName = userData?.lastName;
const firstName = userData?.firstName;
const phone = userData?.phone;
const permissionsArray = fetchedPermissions.map((perm) => perm.id);
const [billingInfo, setBillingInfo] = useState(null);
const [billingType, setBillingType] = useState("individual");
const { initPaymentSheet, presentPaymentSheet } = useStripe();
// Extract parameters from route or provide default values
const {
name = "Unnamed Business",
address = [],
additionalAddress = "",
onlineServices = false,
category = "",
selectedSubcategory = "",
email = "",
plan = "",
region,
} = route.params || {};
const [image, setImage] = useState(null);
const updateBillingInfoAndFinalize = async (info) => {
console.log("info " + JSON.stringify(info));
setBillingInfo(info);
handleFinalize(info);
};
const goToBillingInfo = () => {
navigation.navigate("BillingInfoScreen", {
billingInfo,
billingType,
setBillingType,
onSaveAndFinalize: updateBillingInfoAndFinalize,
});
};
const handleSubscription = async (info) => {
return await addSubscription(
plan,
email,
info,
billingType,
t,
initPaymentSheet,
presentPaymentSheet
);
};
const requestPermissions = async () => {
const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (status !== "granted") {
Alert.alert(t("permission_denied_title"), t("permission_denied_message"));
}
};
const pickImage = async () => {
// 1. Ask for media-library permissions
await requestPermissions();
try {
// 2. Launch picker, ask for base64
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64: true, // ← add this
});
// 3. Handle cancellation
if (result.canceled) {
console.log("No image was selected.");
return;
}
// 4. Build a data URI from the base64 payload
const { base64 } = result.assets[0];
const dataUri = `data:image/jpeg;base64,${base64}`;
console.log("Selected Image data URI:", dataUri);
// 5. Store it in state for both preview and upload
setImage(dataUri);
} catch (e) {
console.error("Image Picker Error:", e);
Alert.alert(t("error_title"), t("image_upload_failed_message"));
}
};
const uploadImage = async (uri) => {
try {
// Convert image to Blob format
const response = await fetch(uri);
const blob = await response.blob();
// Generate a unique file name using UUID
const imageName = `${uuid.v4()}.jpg`;
// Upload image to Firebase Storage
const imageRef = ref(storage, `images/${imageName}`);
await uploadBytes(imageRef, blob);
// Get the download URL
const downloadURL = await getDownloadURL(imageRef);
return downloadURL;
} catch (e) {
console.error("Image Upload Error:", e);
return null;
}
};
const handleFinalize = async (info) => {
if (image) {
let paymentDone = plan.name === "FREE";
if (!paymentDone) {
paymentDone = await handleSubscription(info);
console.log("paymentDone " + paymentDone);
}
if (paymentDone) {
const downloadURL = await uploadImage(image);
if (downloadURL) {
const teamMember = [
{
id: 1, // id unic pentru fiecare membru
firstName: firstName,
lastName: lastName,
email: email,
msisdn: phone,
permissions: permissionsArray,
service_id: "",
},
];
const businessId = await addBusiness({
name: name,
email: email,
address: address,
country: address.length > 0 ? address[0].country : "",
city: address.length > 0 ? address[0].city : "",
region2: address.length > 0 ? address[0].region : "",
images: [downloadURL],
tags: [category],
recommended: "false",
subcategory: [selectedSubcategory],
description: "",
phone_number: "",
services: "",
plan: plan.name,
teamMembers: teamMember,
region: [region],
onlineServices: onlineServices,
additionalAddress: additionalAddress,
});
await addUserToBusiness(email, businessId);
navigation.navigate("BusinessHomeTabs");
} else {
Alert.alert(t("error_title"), t("image_upload_failed_message"));
}
} else {
Alert.alert(t("payment_error_title"), t("payment_error_message"));
}
} else {
Alert.alert(t("error_title"), t("choose_image_message"));
}
};
return (
{!image && (
{t("choose_image_presentation")}
{t("add_images_later")}
)}
{image && (
{t("preview_business")}
{t("presentation_description")}
0
? address[0].formattedAddress || address[0].name
: t("no_address"),
images: [image],
tags: [category],
rating: 5,
no_ratings: 23,
}}
widthSize={300}
/>
)}
);
};
const localStyles = ScaledSheet.create({
anotherImage: {
alignItems: "center",
justifyContent: "center",
},
});
export default LogoScreen;
Подробнее здесь: https://stackoverflow.com/questions/797 ... m-an-album
Приложение для iOS опубликовано в сбое App Store после того, как я выберу изображение из альбома ⇐ IOS
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
IOS App Store продолжает устанавливать версию приложения TestFlight вместо версии App Store
Anonymous » » в форуме IOS - 0 Ответы
- 65 Просмотры
-
Последнее сообщение Anonymous
-