f-miyu / Plugin.CloudFirestore

MIT License
122 stars 44 forks source link

how to setting timestampsInSnapshots #4

Open haya1992 opened 5 years ago

haya1992 commented 5 years ago

target OS is iOS. build and run on simulator.

Executing the following statement IDocumentSnapshot xxx = await CrossCloudFirestore.Current.Instance.GetDocument(strPath).GetDocumentAsync().ConfigureAwait(false);

simulator is no response... debug log is 2019-01-16 13:14:43.927856+0900 XXXXXXX.iOS[29560:384941] 5.8.0 - [Firebase/Firestore][I-FST000001] The behavior for system Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:

let db = Firestore.firestore() let settings = db.settings settings.areTimestampsInSnapshotsEnabled = true db.settings = settings

With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example:

// old: let date: Date = documentSnapshot.get("created_at") as! Date // new: let timestamp: Timestamp = documentSnapshot.get("created_at") as! Timestamp let date: Date = timestamp.dateValue()

Please audit all existi ng usages of Date when you enable the new behavior. In a future release, the behavior will be changed to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.

Android is no problem.

AntvissMedia commented 5 years ago

The README file tells you how to do it. You do not have to set this in your native projects. Set it in App.xaml.cs in the OnStart() method with:

CrossCloudFirestore.Current.Instance.FirestoreSettings = new FirestoreSettings
{
    AreTimestampsInSnapshotsEnabled = true
};