question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash: JSON value of type NSDate cannot be converted to a date

See original GitHub issue

Hello!

I’m scheduling multiple notifications, but sometimes (that’s the worst part; it’s just sometimes) it crashes and throws this error:

JSON value '2016-05-25 04:00:00 +0000' of type NSDate cannot be converted to a date

Here is the code used to schedule:

static scheduleNotification(quoteDate, quoteHours, quoteOfDay){
    let notifDate = new Date(quoteDate);
    notifDate.setHours(quoteHours.hour, quoteHours.mins, 0);
    let message = '"'+quoteOfDay.frase + '" - ' + quoteOfDay.autor;
    PushNotification.localNotificationSchedule({
        id: 0,
        message: message,
        date: notifDate
    })
}

I’ve tried to use “date: new Date(notifDate)”, but no lucky. Any ideas?

Thank you

Edit:

It seems to be related with this issue: https://github.com/facebook/react-native/issues/4049

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
ammichaelcommented, May 6, 2016

Hey guys, anyone having this problem, it might be solved passing a date in ISO 8601 format. Just use “.toISOString()”. That works for me, all the crashes are gone! (:

4reactions
superandrew213commented, Jul 7, 2016

For Android use:

date: new Date(Date.now() + (10 * 1000))

for iOS use:

date: new Date(Date.now() + (10 * 1000)).getTime()

Is there a reason why we are doing this?

Notifications.localNotificationSchedule = function(details: Object) {
    if ( Platform.OS === 'ios' ) {
        this.handler.scheduleLocalNotification({
            fireDate: details.date,
            alertBody: details.message
        });
    } else {
        details.fireDate = details.date.getTime();
        delete details.date;
        this.handler.scheduleLocalNotification(details);
    }
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON date to NSDate Issue - objective c - Stack Overflow
And I'm trying to convert it to NSDate. - (NSString *)dateFromString:(NSString *)datestring{ // Convert string to date object NSDateFormatter *dateFormat ...
Read more >
iOS app crashes while setting value of field in date format
The SFRestAPI class cannot convert that date filed into proper serialized JSON and ... reason: 'Invalid type in JSON write (__NSDate)'
Read more >
Core Data Error with NSDate | Apple Developer Forums
hello: Can someone tell me why I am getting a crash when saving a date attribute in Core Data: Unacceptable type of value...
Read more >
[Solved]-Swift 4 - Cannot assign value of type 'NSDate' to type ...
Coding example for the question Swift 4 - Cannot assign value of type 'NSDate' to type 'Date?' ONLY on Physical Device.
Read more >
Understanding Dates - Maddysoft iOS
// Swift let now = Date() // Objective-C NSDate *now = [NSDate date];. This seems simple enough but this little line of code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found