Deployed App (both ios and android) crashes but there are no errors in development.

Please provide the following:

  1. SDK Version: 46.0.16
  2. Platforms(Android/iOS/web/all): All
  3. Add the appropriate “Tag” based on what Expo library you have a question on.
    expo-barcode-scanner AND expo-av

My code crashes when I visit this screen… It does just fine on the Emulator.

I am at a loss for what this is - Any thoughts are appreciated!

Code is below.

Thanks.
Matt

import React, { useState, useEffect } from ‘react’;
import { Text, View, StyleSheet, Button, TouchableOpacity } from ‘react-native’;
import { BarCodeScanner } from ‘expo-barcode-scanner’;
import { Audio } from ‘expo-av’;
import { auth, firebase } from “…/Firebase/Config”;

import { collection, addDoc, query, where, getDocs, deleteDoc, doc, setDoc, getDoc, updateDoc, arrayUnion, FieldValue } from “firebase/firestore”;

import Pass from “./Pass”;
import { createUserWithEmailAndPassword } from ‘firebase/auth’;
import { sqrt } from ‘react-native-reanimated’;

// import { useNavigation } from ‘@react-navigation/native’;

const Scanner2 = ({ route, navigation }) => {

const { userinformation, teacherid, coursename, classid, teacher, Selectedclassdestination, youcangetpass, section, currentlocation, school, state, town, locationdestination, firstname, lastname, ledby, drinkofwater, exclusivetime, donewithworkpass, currentsessionid, bathroomtime, nonbathroomtime, bathroompassinuse, totalinlineforbathroom, id, passid,teacheridforreturn, maxstudentsonphonepass, newlocation, timeallowed, adjustmentandoverunder, total2, getcurrentdifference, day, leftclass2, expectedreturn, endofclasssession,} = route.params;

//‘day’ confirms that persoan has already visited pass and is coming back to zap out

const [leavetimeGlobal, setLeavetimeGlobal] = useState();
const [returntimeGlobal, setReturntimeGlobal] = useState(“”);

const [sound, setSound] = React.useState();
const [eligible, setEligible] = React.useState(true);
const [hasPermission, setHasPermission] = useState(null);
const [scanned, setScanned] = useState(false);
const [text, setText] = useState(‘Not yet scanned’);

const [leftclass, setLeftclass] = useState();

const [howmanypeople, setHowmanypeople] = useState();
const [howmanypeople2, setHowmanypeople2] = useState();
const [takenameoffwaitlist, setTakenameoffwaitlist] = useState();

const [phonehowmanypeople, setPhonehowmanypeople] = useState();
const [phonehowmanypeople2, setPhonehowmanypeople2] = useState();
const [phonetakenameoffwaitlist, setPhonetakenameoffwaitlist] = useState();
const [rightnow, setRightnow] = useState();

const [ontime, setOntime] = useState();

const [adjust, setAdjust] = useState();
const [levell, setLevell] = useState();
const [overunderr, setOverunderr] = useState();

const [penaltyminutes, setPenaltyminutes] = useState();

const [realtimeleave, setRealtimeleave] = useState();
const [currentdate, setCurrentdate] = useState();

const [timelimit, setTimelimit] = useState();
const [completed, setCompleted] = useState();

const [currenttime, setCurrenttiime] = useState();

// useEffect(() => {

// if (locationdestination == “Bathroom”) {
// setAllottedtime(bathroomtime);
// } else if (locationdestination == “Get Drink of Water”) {
// setAllottedtime(drinkofwater);
// } else {
// setAllottedtime(nonbathroomtime);
// }
// }, );

useEffect(() => {
console.log("1Did it get this far? ");
if (typeof completed != “undefined”) {
console.log("2Did it get this far? ");
navigation.navigate(“Mainmenustudent”, {
teacherid: teacherid, coursename: coursename, classid: classid, teacher: teacher, Selectedclassdestination: Selectedclassdestination, youcangetpass: youcangetpass, section: section, currentlocation: currentlocation, school: school, state: state, town: town, locationdestination: locationdestination, firstname: firstname, lastname: lastname, teacherid: teacherid, coursename: coursename, Selectedclassdestination: Selectedclassdestination, ledby: ledby, drinkofwater:drinkofwater, exclusivetime: exclusivetime, donewithworkpass: donewithworkpass, bathroomtime: bathroomtime, nonbathroomtime: nonbathroomtime, bathroompassinuse: bathroompassinuse,
currentsessionid: currentsessionid, id: id, passid: passid, teacheridforreturn: teacheridforreturn, leftclass: leftclass, expectedreturn: expectedreturn, maxstudentsonphonepass: maxstudentsonphonepass, newlocation: newlocation, timeallowed: timeallowed, adjustmentandoverunder: adjustmentandoverunder, total2: total2, getcurrentdifference: getcurrentdifference, rightnow: rightnow, currentdate:currentdate, realtimeleave:realtimeleave
});

}
}, [completed]);

useEffect(() => {

navigation.setOptions({
    headerLeft: () => (
        <TouchableOpacity >
            <Text accessibilityLabel="Guest" style={styles.error}>
            </Text>
        </TouchableOpacity>
    ),
});

}, );

useEffect(() => {
console.log("3Did it get this far? ");
if (id && classid) {
console.log("4Did it get this far? ");
getadjustment();
}
}, );

const getadjustment = () => {

console.log("5Did it get this far? ");

if (id && classid) {
  console.log("6Did it get this far? ");
  const docRef = doc(firebase, "users", id);

  const docData = getDoc(docRef)

    .then((docSnap) => {
      let idd = classid;
      let object = docSnap.data();

      const whatever = object[idd].adjustments;
      const penaltyminutes = object[idd].penaltyminutes;
      const ovunder = object[idd].overunder;
      const level = object[idd].level;

      setAdjust(whatever);
      setPenaltyminutes(penaltyminutes);
      setOverunderr(ovunder);
      setLevell(level);
     
    })
}

};

useEffect(() => {
console.log("7Did it get this far? ");
if (classid.length > 3) {
console.log("8Did it get this far? ");
checkDatabaseData2();
}
}, );

useEffect(() => {
console.log("9Did it get this far? ");
setCurrenttiime(Date.now())

}, );

useEffect(() => {
console.log(expectedreturn, "10Did it get this far? ");
if (expectedreturn > 10) {
console.log("10Did it get this far? ");
if (currenttime < expectedreturn) {

    console.log("22this was run");
    setOntime(true);
  } else {
    console.log("23this was run");
    setOntime(false);
  }
}

}, [currenttime]);

async function checkDatabaseData2() {
console.log("12Did it get this far? ");

const docRef = doc(firebase, "classesbeingtaught", classid);

const docSnap = await getDoc(docRef);

if (docSnap.exists()) {
  setHowmanypeople2(docSnap.data().inusebathroompass)
  setPhonehowmanypeople2(docSnap.data().inuseexclusivephonepass)

} else {
  // doc.data() will be undefined in this case

}

}

// const navigation = useNavigation();

//shortcut() to be used in development

const developmentshortcut = () => {

var r = new Date();
var s = Date.now();

setRightnow(s);
setLeavetimeGlobal(r);
setLeftclass(s);

setScanned(true);
setText('gKisPqjbSdRFQ8Ix6gKjnbHYKAp2');

}

useEffect(() => {

console.log("13Did it get this far? ");
return sound
  ? () => {
 
    sound.unloadAsync();
  }
  : undefined;

}, [sound]);

useEffect(() => {
console.log("14Did it get this far? ");
setText(“Not yet scanned”);
setScanned(false);
}, );

async function playSound() {
const { sound } = await Audio.Sound.createAsync(
require(‘…/…/assets/Confirm.mp3’)
);
setSound(sound);

await sound.playAsync();

}

async function returnfinalizehallpass() {

console.log("15Did it get this far? ");

if (Date.now() > endofclasssession) {

var t = endofclasssession;
var r = new Date(t);

console.log(“1 was this run?,”, t, r, “endofclasssession”, “newDate”)

if (locationdestination == "Bathroom") {
const currentdiff = ((expectedreturn - t) / 60000);

const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };

setHasPermission(null);
setText("Not yet scanned");
setScanned(false);


await updateDoc(doc(firebase, "passes", passid), {
  returned: t,
  timereturned: r.toLocaleTimeString([], { hour12: true }),
  returnedbeforetimelimit: ontime,
  differenceoverorunderinminutes: currentdiff,

}).catch((error) => {
  console.log(error);
}),


  await updateDoc(doc(firebase, "users", id), {
    [classid]: percentsss,
    passid: "",
    status: "",

  }).catch((error) => {
    console.log(error);
  }),

  await updateDoc(doc(firebase, "classesbeingtaught", classid), {
    inusebathroompass: howmanypeople2 - 1,
  }).catch((error) => {
    console.log(error);

  }).then(async () => {

    setHasPermission(null);
    setText("Not yet scanned");
    setScanned(false);
    setCompleted(true);

  })

} else {
   
  const currentdiff = ((expectedreturn - t) / 60000);

  const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };

  await updateDoc(doc(firebase, "passes", passid), {
    returned: t,
    timereturned: r.toLocaleTimeString([], { hour12: true }),
    returnedbeforetimelimit: ontime,
    differenceoverorunderinminutes: currentdiff,

  }).catch((error) => {
    console.log(error);
  }),


    await updateDoc(doc(firebase, "users", id), {
      [classid]: percentsss,
      passid: "",
      status: "",

    }).catch((error) => {
      console.log(error);
    }).then(async () => {


        setHasPermission(null);
        setText("Not yet scanned");
        setScanned(false);
        setCompleted(true);
    })

}

}
else {

  var r = new Date();
  var t = Date.now();

  console.log("2 was this run?,", t, r, "endofclasssession", "newDate")

  if (locationdestination == "Bathroom") {
    const currentdiff = ((expectedreturn - t) / 60000);

    const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };

    setHasPermission(null);
    setText("Not yet scanned");
    setScanned(false);


    await updateDoc(doc(firebase, "passes", passid), {
      returned: t,
      timereturned: r.toLocaleTimeString([], { hour12: true }),
      returnedbeforetimelimit: ontime,
      differenceoverorunderinminutes: currentdiff,

    }).catch((error) => {
      console.log(error);
    }),


      await updateDoc(doc(firebase, "users", id), {
        [classid]: percentsss,
        passid: "",
        status: "",

      }).catch((error) => {
        console.log(error);
      }),

      await updateDoc(doc(firebase, "classesbeingtaught", classid), {
        inusebathroompass: howmanypeople2 - 1,
      }).catch((error) => {
        console.log(error);

      }).then(async () => {

        setHasPermission(null);
        setText("Not yet scanned");
        setScanned(false);
        setCompleted(true);
    
      })

    } else {
        console.log("37was this run?,",  text, scanned,  ontime, expectedreturn, "text, scanned,  ontime, expectedreturn,")

      const currentdiff = ((expectedreturn - t) / 60000);

      const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };
    
      await updateDoc(doc(firebase, "passes", passid), {
        returned: t,
        timereturned: r.toLocaleTimeString([], { hour12: true }),
        returnedbeforetimelimit: ontime,
        differenceoverorunderinminutes: currentdiff,
  
      }).catch((error) => {
        console.log(error);
      }),
  
  
        await updateDoc(doc(firebase, "users", id), {
          [classid]: percentsss,
          passid: "",
          status: "",
  
        }).catch((error) => {
          console.log(error);
        }).then(async () => {
  

            setHasPermission(null);
            setText("Not yet scanned");
            setScanned(false);
            setCompleted(true);
        })


}

}
}
async function returnmakephonepass() {

if (Date.now() > endofclasssession) {

  var t = endofclasssession;
  var r = new Date(t);

const currentdiff = ((expectedreturn - t) / 60000);

const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };

await updateDoc(doc(firebase, "passes", passid), {
  returned: t,
  timereturned: r.toLocaleTimeString([], { hour12: true }),
  returnedbeforetimelimit: ontime,
  differenceoverorunderinminutes: (expectedreturn - t) / 60000,

}).catch((error) => {
  console.log(error);
}),

await updateDoc(doc(firebase, "users", id), {
  [classid]: percentsss,
  passid: "",
  status: "",
}).catch((error) => {
  console.log(error);
});


  await updateDoc(doc(firebase, "classesbeingtaught", classid), {
    inuseexclusivephonepass: phonehowmanypeople2 - 1,
  }).catch((error) => {
    console.log(error);

  }).then(async () => {

    setHasPermission(null);
    setText("Not yet scanned");
    setScanned(false);
    setCompleted(true);
  })

} else {

var r = new Date();
var t = Date.now();

const currentdiff = ((expectedreturn - t) / 60000);

const percentsss = { id: classid, penaltyminutes: penaltyminutes, overunder: overunderr + currentdiff, adjustments: adjust, level: levell };

await updateDoc(doc(firebase, “passes”, passid), {
returned: t,
timereturned: r.toLocaleTimeString(, { hour12: true }),
returnedbeforetimelimit: ontime,
differenceoverorunderinminutes: (expectedreturn - t) / 60000,

}).catch((error) => {
console.log(error);
}),

await updateDoc(doc(firebase, “users”, id), {
[classid]: percentsss,
passid: “”,
status: “”,
}).catch((error) => {
console.log(error);
});

await updateDoc(doc(firebase, "classesbeingtaught", classid), {
  inuseexclusivephonepass: phonehowmanypeople2 - 1,
}).catch((error) => {
  console.log(error);

}).then(async () => {

  setHasPermission(null);
  setText("Not yet scanned");
  setScanned(false);
  setCompleted(true);
})

}
}

useEffect(() => {

console.log("16Did it get this far? ", locationdestination, ontime, text, teacheridforreturn);
if (text != "Not yet scanned" && typeof ontime != "undefined") {

  console.log("32was this run?", expectedreturn, ontime, text, scanned, "expectedreturn, ontime, text, scanned,")
  if (text == teacheridforreturn && scanned) {
    playSound();
    if (locationdestination == "Break From Work Pass") {
      returnmakephonepass();
    } else {
      returnfinalizehallpass();
    }

  } if (teacheridforreturn != text && scanned) {

    setText('Not yet scanned');
    alert("You have scanned the wrong @RCode");
  }
}

}, [ontime, text]);

// Request Camera Permission

useEffect(() => {
console.log("17Did it get this far? ");
const getBarCodeScannerPermissions = async () => {
const { status } = await BarCodeScanner.requestPermissionsAsync();
setHasPermission(status === ‘granted’);
};

getBarCodeScannerPermissions();

}, );

// What happens when we scan the bar code
const handleBarCodeScanned = ({ type, data }) => {

console.log("18Did it get this far? ");
 
  var r = new Date();
  var s = Date.now();

  setRightnow(s);
  setLeavetimeGlobal(r);
  setLeftclass(s);

  setScanned(true);
  setText(data);

};

return (


<BarCodeScanner
onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
style={{ height: 300, width: 400 }} />
{scanned && <TouchableOpacity onPress={() => setScanned(false)}>}

  </View>

{/*
{text}{‘\n’}{teacheridforreturn}{‘\n’}{ontime}{‘\n’}{scanned?“hello”:“goodbye”} */}

<TouchableOpacity
onPress={() => developmentshortcut()}>Mr Jones Shortcut

);
}

export default Scanner2;

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: ‘#222’,
alignItems: ‘center’,
justifyContent: ‘center’,
},
maintext: {
fontSize: 16,
margin: 20,
color: “#fff
},
maintext1: {
fontSize: 16,
margin: 20,
color: “#ff0000
},
barcodebox: {
alignItems: ‘center’,
justifyContent: ‘center’,
height: 400,
width: 300,
overflow: ‘hidden’,
borderRadius: 30,
backgroundColor: ‘#E43522
},
error5: {

backgroundColor: '#000',
color: "#FFF",
marginLeft: "3%",
marginRight: "3%",
fontSize: 17,
fontWeight: 'bold',
textAlign: "center",

},
});

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.