久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 Firebase 的 iOS API 獲取服務(wù)器時(shí)間戳?

How do I get a server timestamp from Firebase#39;s iOS API?(如何從 Firebase 的 iOS API 獲取服務(wù)器時(shí)間戳?)
本文介紹了如何從 Firebase 的 iOS API 獲取服務(wù)器時(shí)間戳?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)使用 Firebase 的 iOS 應(yīng)用,目前有一些字典,其中的鍵是 NSDate 對(duì)象.這樣做的一個(gè)明顯問題是 NSDate 從設(shè)備的系統(tǒng)時(shí)間中提取,這不是通用的.

I have an iOS app that uses Firebase and currently has a few dictionaries with keys that are NSDate objects. The obvious issue with this is that NSDate draws from the device's system time, which is not universal.

這樣,使用 Firebase 的 iOS API 獲取服務(wù)器時(shí)間戳(類似于 Web API 的 Firebase.ServerValue.TIMESTAMP)以便我可以按時(shí)間順序?qū)ψ值滏I進(jìn)行排序的最佳方法是什么?

With that, what's the best way to get a server timestamp (similar to Firebase.ServerValue.TIMESTAMP for the Web API) using Firebase's iOS API so that I can sort my dictionary keys chronologically?

我也知道 childByAutoID 生成的 ID 的時(shí)間順序,但我無法找出在代碼中對(duì)它們進(jìn)行排序的正確方法.雖然它們可能按時(shí)間順序返回,但只要在它們上調(diào)用 allKeys 之類的東西,順序就會(huì)消失.

I'm also aware of the chronological nature of IDs generated by childByAutoID, but I can't figure out the proper way to sort these in code. While they may be returned in chronological order, any time something like allKeys is called on them, the order goes out the window.

任何有關(guān)此問題的幫助將不勝感激!

Any help with this issue would be greatly appreciated!

推薦答案

更新: 在 Firebase 3.0 + Swift 中,你可以使用FIRServerValue.timestamp().在 Objective-C 中,這是 [FIRServerValue timestamp].

Update: In Firebase 3.0 + Swift, you can use FIRServerValue.timestamp(). In Objective-C this is [FIRServerValue timestamp].

在 Swift 中,您現(xiàn)在可以在 Firebase 2.0.3+(3.0 之前)中使用 FirebaseServerValue.timestamp().

In Swift, you can now use FirebaseServerValue.timestamp() with Firebase 2.0.3+ (before 3.0).

iOS 中 Firebase.ServerValue.TIMESTAMP 的等效項(xiàng)是 kFirebaseServerValueTimestamp.目前,這只適用于 Objective-C 而不是 Swift.

The equivalent for Firebase.ServerValue.TIMESTAMP in iOS is kFirebaseServerValueTimestamp. Right now, this only works for Objective-C and not Swift.

在 Swift 中,您可以使用

In Swift, you can create your own global timestamp with

let kFirebaseServerValueTimestamp = [".sv":"timestamp"]

然后您將能夠以相同的方式使用 kFirebaseServerValueTimestamp.

and then you'll be able to use kFirebaseServerValueTimestamp in the same way.

但你只能將它用作節(jié)點(diǎn)的值或優(yōu)先級(jí).您將無法將其設(shè)置為密鑰名稱(盡管我不相信您也可以在 Web API 中).

But you can only use this as the value or priority of a node. You won't be able to set it as the key name (although, I don't believe you could in the Web API either).

一般來說,在字典上調(diào)用 allKeys 不會(huì)> 保證順序. 但是,如果您在節(jié)點(diǎn)上使用 childByAutoID,則可以通過按字典順序?qū)?allKeys 返回的 NSArray 進(jìn)行排序來恢復(fù)正確的順序.這樣的事情會(huì)起作用:

In general, calling allKeys on a dictionary does not guarantee order. But if you're using childByAutoID at a node, you can get back the right order by ordering the NSArray returned by allKeys lexicographically. Something like this would work:

[ref observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
    NSDictionary *value = snapshot.value;
    NSLog(@"Unsorted allKeys: %@", value.allKeys);
    NSArray *sortedAllKeys = [value.allKeys sortedArrayUsingSelector:@selector(compare:)];
    NSLog(@"Sorted allKeys: %@", sortedArray);
}];

這類似于對(duì) NSArray 按字母順序進(jìn)行排序,但是在對(duì)自動(dòng)生成的 ID,您確實(shí)想要本地化或不區(qū)分大小寫的排序,因此您使用 compare: 而不是 localizedCaseInsensitiveCompare:

This is similar to sorting an NSArray alphabetically, but when sorting the auto-generated IDs, you do not want localized or case insensitive sort, so you use compare: instead of localizedCaseInsensitiveCompare:

這篇關(guān)于如何從 Firebase 的 iOS API 獲取服務(wù)器時(shí)間戳?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Stop a UITableView from automatically scrolling(阻止 UITableView 自動(dòng)滾動(dòng))
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運(yùn)行時(shí),使用 iOS 6.0 SDK 并為 iOS 5 Target 構(gòu)建會(huì)導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
主站蜘蛛池模板: 求个av网址 | 亚洲免费在线 | 亚洲一区二区三区四区五区中文 | 日韩一区不卡 | 日韩久久久久久 | 喷水毛片 | 欧美日韩国产传媒 | 欧美色欧美亚洲另类七区 | 午夜影院在线播放 | 国产高清精品在线 | 欧产日产国产精品99 | 国产日韩欧美91 | 中文一区 | 亚洲一区二区三区免费视频 | 免费黄色av网站 | 毛片a级毛片免费播放100 | www.伊人.com | www久久久 | 亚洲一区中文字幕在线观看 | 国产精品一级 | 国产欧美日韩一区二区三区 | av二区三区| 一级做a爰片久久毛片 | 亚洲国产成人av好男人在线观看 | 久久久久久久久中文字幕 | 成人黄页在线观看 | 美日韩免费视频 | 亚洲成av人片在线观看 | 免费在线观看一区二区三区 | 精品欧美激情在线观看 | 久久伊 | 狠狠插天天干 | 在线看h| 久草成人| www.亚洲 | www.日本在线播放 | 亚洲成av人片在线观看无码 | 色永久| 精品国产一区二区三区av片 | 亚洲区一区二 | 国产在线aa |