Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No Calendar has been set" after authorization until App is restarted #55

Closed
Prudwell opened this issue Mar 24, 2017 · 3 comments
Closed

Comments

@Prudwell
Copy link

I'm on iOS and in my app I authorize the calendar store, but I cannot set events until I restart the app. It still acts like the calendar system has not been authorized when I try to add events directly after authorization. Is there some way I'm supposed to reinitialize the calendar object so that it can properly see the new settings?

Cheers

@wmcmahan
Copy link
Owner

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

@Prudwell
Copy link
Author

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

@Prudwell
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants