Tag: firebase云消息传递

如何从iOS Today Extension访问当前的Firebase用户?

我们正在与Firebase合作的iOS应用程序之上构build一个今天的小部件。 但是,我们正在努力从扩展中访问当前login的用户。 主应用程序中的用户是匿名的,因此不能通过共享容器传递凭据。 唯一的办法,我发现传递uid并生成自定义令牌login,但我希望find更好的方式来分享我的主要应用程序和应用程序扩展之间的FIRUser。 什么是实现这个目标的最好方法?

负面的时间戳得到错误的post列表

我被困在一个棘手的小问题上,所以请帮助 (此代码有效)我使用下面的代码来获取最新的post,使用negativeTimestamp:哪个是使用FIRServer,然后查询和负面。 FIRDatabase.database().reference().child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryEnding(atValue: startValue – 1, childKey: "negativeStamp").observe(.childAdded, with: {(snapshot) in 我也使用下面的查询来获得所有的post, 这完美的作品 。 我最终得到最新的项目。 ref.child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryLimited(toFirst: 5).observeSingleEvent(of: .value, with: {(snapshot) in 当我尝试获取tableView的接下来的5个元素时,问题就出现了。 我无法顺序查询5个元素? 我正在使用这个代码。 Self.timestampArray.last将是tableView中显示的最后一个post。 let endingValue: Int = self.timestampArray.last! let timeIntervalToday: TimeInterval = (NSDate().timeIntervalSince1970) * -1 FIRDatabase.database().reference().child("post").child(animal).queryOrdered(byChild: "negativeStamp").queryEnding(atValue: (endingValue + 1)).observe(.value, with: {(snapshot) in 我也使用这个tableView函数来知道用户何时到达底部 。 希望这不是太多的阅读。 func tableView(_ tableView: UITableView, willDisplay […]

附加Firebase聊天消息

我正在创build一个聊天应用程序,我有一个表格视图单元格中两个用户之间发送的所有消息的列表。 例如,我在两个用户之间共有四个文本,所以我有四个单元格。 但是,我想将单元格分组,因此我只有一个单元格,因为我的loggedInUser只与一个人通信。 不pipe我做什么,邮件都不会追加。 func loadData(){ if (FIRAuth.auth()?.currentUser) != nil{ FIRDatabase.database().reference().child("messages").observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in let loggedInUserData = snapshot if let postsDictionary = snapshot .value as? [String: AnyObject] { for post in postsDictionary { let messages = post.value as! [String: AnyObject] for (id, value) in messages { let info = value as! [String: AnyObject] […]

使用当前的时间戳在此之前查询所有post

我保证一个EASY阅读:) 你好,我现在卡住了。 我想查询从最新的post开始,而不是最旧的post的所有post。 为什么? 因为它是我可以在我的tableView中包含分页的唯一方法。 (这意味着当用户到底时重新加载) 比方说,我有10个post,从最老的#1和最新的#10开始: 1,2,…,10如果我查询限于前5个职位,我得到[1,2,3,4,5]然后我倒过来的数组,它将显示我的桌面视图[5,4,3,2,1]从5开始。 问题 :一旦用户到达tableview的底部,如果我查询下一个5个post,从最后一个post的时间戳开始,我得到… [6,7,8,9,10] 但现在我的表格视图是不正确的,因为它会显示[5,4,3,2,1,10,9,8,7,6]我希望如果我可以使用当前设备date作为时间戳并查询之前的所有post,如下所示:我实质上可以得到[10,9,8,7,6],那么当用户到达底部时: [10,9,8,7,6,5,4,3,2 ,1] let todayTime:TimeInterval = NSDate()。timeIntervalSince1970 FIRDatabase.database().reference().child("post").child(animal).queryOrderedByValue().queryEnding(atValue: todayTime, childKey: "datePost").queryLimited(toLast: 5).observe(.value, with: {(snapshot) in

在UITableViewCell中的UIImageView或AVPlayer(照片或video)

1)我有一个UITableView的应用程序。 这个单元格有一些像UILabel , UIButton (喜欢,说明等)的内容,它也应该存储图像或video(取决于types的职位(如instagram经典邮政))。 所以细胞可以是两种types之一:有video或有照片。 其他信息,限制,尺寸等是相似的。 目前,我只有一个与UIView自定义单元格types(照片/video)。 而且我在这个UIView上添加了AVPlayer和UIImageView图层。 它有效,但我认为这是如何做到这一点的一个坏方法。 另外这是非常糟糕的逻辑与图层。 如何正确地做到这一点? 我应该有2个自定义单元格types? 或者,也许有一些图书馆存在吗? 2)我正在从Firebase-storage下载数据。 这个操作是asynchronous的。 所以我在我的PostItem存储MediaAspectRatio ( width/height )。 我使用它来缩放UIView在单元格出现不裁剪媒体之前。 我也不确定,这是正确的逻辑。 任何build议表示赞赏。 谢谢。

Firebase imageview数组

在我的应用程序中,我正在使用自定义图像数组视图。 用户上传的每个post的许多图像应该是以旋转木马般的方式显示的多个图像。 在firebase,我有价值从图像到imageFive { "image" : "W585B.jpg", "imageFive" : "", "imageFour" : "", "imageThree" : "", "imageTwo" : "", } 正如你在这个例子中看到的,只有一个值有一个string。 用户可以发布一到五个图像。 我想追加用户上传的许多图像并将其显示在传送带上。 这是我现在所拥有的。 var imageArray = [UIImage]() override func viewDidLoad() { super.viewDidLoad() if let stringImage = self.imageNames { let imageRef = storage.reference(forURL: "gs://gsignme-14416.appspot.com/images/\(stringImage)") imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> […]

Swift Firebase按距离sorting

我正在尝试按距离sorting我的数组。 我已经把所有东西都吸引到了距离的距离,但是不确定如何从最靠近用户的位置到最远的地方进行sorting。 我已经使用MKMapItem的下面的代码,但不知道如何应用到我当前的数组。 func sortMapItems() { self.mapItems = self.mapItems.sorted(by: { (b, a) -> Bool in return self.userLocation.location!.distance(from: a.placemark.location!) > self.userLocation.location!.distance(from: b.placemark.location!) }) } Firebase通话 databaseRef.child("Businesses").queryOrdered(byChild: "businessName").observe(.childAdded, with: { (snapshot) in let key = snapshot.key if(key == self.loggedInUser?.uid) { print("Same as logged in user, so don't show!") } else { if let locationValue = snapshot.value as? […]

用swift从应用程序ioscaching中读取图像

我目前正在从我的firebase存储中读取图像 – 这工作正常。 从存储中读取图像时,我设置了一个caching来读取图像: // Storage.imageCache.object(forKey: post.imageUrl as NSString) static func getImage(with url: String, completionHandler: @escaping (UIImage) -> ()) { if let image = imageCache.object(forKey: url as NSString) { print("CACHE: Unable to read image from CACHE ") completionHandler(image) } else { let ref = FIRStorage.storage().reference(forURL: url) ref.data(withMaxSize: 2 * 1024 * 1024) { (data, error) […]

Firebase .on()侦听器会导致Cordova iOS应用崩溃

我做了一个空白,全新的cordova应用程序(-v 6.3.1),并为iOS构build。 该应用程序除了以下内容什么都不做 var ref = new Firebase('url-to-firebase-leaf-node-with-4000-children'); ref.on("child_added", function(child, prev) { console.log("here"); }); 部署到iPhone。 该应用程序崩溃,Xcode引用以下内容: WebThread (7): EXC_BAD_ACCESS (code=1, address=0xbbadbeef)在bmalloc::VMHeap::grow() 。 如果我这样做: var ref = new Firebase('url-to-firebase-leaf-node-with-100-children'); 那么应用程序不会崩溃。 这显然是一个记忆问题,但是如何解决呢? 从4000个子节点中抽取1.5Mb的数据,我不会想象这应该占用所有可用的内存。 请避免不提取所有数据的build议 – 应用程序需要所有的数据,并在Android上正常工作。

Firebase iOS无法获取默认标记Error Domain = com.firebase.iid Code = 6“(null)”

当我运行我的Firebase应用程序时,我不断收到标题中的错误。 我相信这是阻止我执行数据库查询。 例如, FIRAuth.auth()?.currentUser在login后是nil 。 经过研究,我相信我必须为我的项目添加一个钥匙链。 当我打开(xCode – >目标 – >function)中的钥匙串共享时,我在下面的屏幕上显示错误。 我需要在Keychain Access(应用程序)中添加某种证书吗? 我没有使用消息function,所以我不认为我需要添加这里build议的.p12证书。 我需要在Firebase控制台中添加某种钥匙串吗? 我已经确认我的BundleID是正确的。 我需要在这里改变一些东西: 我已经按照这里的所有设置步骤。