Git Product home page Git Product logo

Comments (3)

wmcmahan avatar wmcmahan commented on May 19, 2024

Hey @Prudwell, are you waiting for the authorizeEventStore methods promise to fulfill before trying to save the event?

from react-native-calendar-events.

Prudwell avatar Prudwell commented on May 19, 2024

Yes sir, the render function shouldn't even display the option to save a new event unless the authorizeEventStore has fulfilled as authorized in the componentDidMount

  componentDidMount() {
       RNCalendarEvents.authorizationStatus()
           .then(status => {
               this.setState({authorizationStatus: status})

               if(status == 'undetermined'){
                   RNCalendarEvents.authorizeEventStore()
                       .then((res) => {
                           if(res == "authorized"){
                               this.setState({authorizationStatus: res})
                           }
                       })
               }
           })
           .catch(error => {
               // handle error
           });
   }

   render(){
        if(this.state.authorizationStatus == "authorized") {
            let singleItemFromState = this.props.items.get(this.props.rowID)

            return (
                <Animated.View key={this.props.reminderObject.reminderRowID}
                               style={[styles.container, {backgroundColor: "rgba(52,52,52,0.5)"},
                                   {transform: [{translateY: this.state.offset}]}]}>
                    <View style={{
                        width: 450,
                        height: 320,
                        justifyContent: "center",
                        alignItems: "center",
                        backgroundColor: "white"
                    }}>
                        <DatePickerIOS
                            style={{height: 200, width: 450}}
                            date={this.state.dateValue}
                            mode="datetime"
                            minuteInterval={1}
                            onDateChange={(newDateObject) => this.setState({dateValue: newDateObject})}
                        />
                        <View style={{flexDirection:"row", justifyContent:"space-between"}}>
                            <Button style={appStyle.itemReminderButton} onPress={this.closeModal.bind(this)}>Go back</Button>
                            <Button style={[appStyle.itemReminderButton]}
                                onPress={this.deleteAndCloseModal.bind(this, singleItemFromState, this.props.reminderObject.reminderRowID, this.state)}>Delete</Button>
                            <Button style={appStyle.itemReminderButton}
                                onPress={this.saveAndCloseModal.bind(this, singleItemFromState, this.props.reminderObject.reminderRowID, this.state)}>Save</Button>
                        </View>
                    </View>
                </Animated.View>
            );
        }
        else{
            return(
                   //some code displaying a link to the iOS settings to enable calendar permission
            )
        }
    }

Even more strange is that this appears to be intermittent (oh joy). I can delete that app in simulator, reinstall it via xcode, complete the authorizeEventStore() action, and sometimes it works right away, other times it throws the promise rejection until I restart the app.

Possible Unhandled Promise Rejection (id: 1):
No calendar has been set.
Error: No calendar has been set.
    at createErrorFromErrorData (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7245:11)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7208:35
    at MessageQueue.__invokeCallback (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7593:10)
    at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7444:8
    at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7363:1)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:7443:1)
    at http://localhost:8081/debuggerWorker.js:71:58

The function that saves the event is now wrapped with RNCalendarEvents.authorizationStatus and it shows the status as authorized even when it throws that no calendar set promise rejection.

I'll update if I find anything new

from react-native-calendar-events.

Prudwell avatar Prudwell commented on May 19, 2024

Alright it seems to be caused by another part of my code that's running on an interval. When my app starts up, it attempts to sync events that it sees in its own database with the events stored in iOS calendar events. That interval attempted to read and save events with no regard for authorizationStatus() and when those failed it somehow made it impossible to save events even after I completed authorizeEventStore().

I don't know how those failures caused future actions to fail (maybe not catching those promise rejections properly) but it's been resolved by just wrapping that code in authorizationStatus() and only running when authorized.

The intermittency of the issue for me I believe depended on whether I authorized the event store before that interval ran.

from react-native-calendar-events.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.