Crash: JSON value of type NSDate cannot be converted to a date
See original GitHub issueHello!
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:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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! (:
For Android use:
for iOS use:
Is there a reason why we are doing this?