Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

Using addListener (willBlur) is crashing on tester's IOS device

$
0
0

I have created an IOS app using React Native. The app consists of a Song Menu screen and a song screen. On the song screen the user is able to press the play button to play the song.

I am currently testing it out using TestFlight. It is working fine on my phone. However, on my friend's phone it keeps crashing. The error is very generic giving RCTFatal as the error.

However, I have narrowed the problem down to code which stops songs from playing when the user navigates away from the Song page.

The relevant code is here:

export default class Song extends Component {

    playAudio = (file) => {
        var s = new Sound('audio/' + file, Sound.MAIN_BUNDLE, (error) => {
             if (error){
                  console.log('error', error)
             } else {
                   s.play(() => {
                         s.release()
                   })
             }
        })

        /* Problem LINE #1 */
        this.willBlurSubscription = this.props.navigation.addListener(
             'willBlur',
             () => s.release()
        )

    }

    /* Problem LINE #2 */
    componentWillUnmount(){
        this.willBlurSubsciption.remove()
    }

    /* Other code here for displaying UI and the clickable audio button which loads the playAudio function. */
    ...
}

When I remove the subscription code above (shown on two lines) then there is no crash. However, the song will not stop playing after the user goes back to the main menu. When I put the lines back in there it crashes for my tester with the RCTFatal error.

Note: The app crashes whether my tester plays the audio file or not, but always when he navigates back to the Song Menu.

What is the problem with my code? Why is it generating such a cryptic error? And why does my IOS device not crash but his does?


Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>