Tag: firebase云消息传递

types“任何”没有下标成员(firebase)

我得到这个错误:“types”任何'没有下标成员“试图运行这段代码时: init(snapshot: FIRDataSnapshot) { key = snapshot.key itemRef = snapshot.ref if let postContent = snapshot.value!["content"] as? String { // error content = postContent } else { content = "" } } 我一直在寻找答案,并找不到一个解决这个问题与FireBase。 我将如何解决这个错误?

您如何正确地从Firebase按时间顺序sorting数据

我试图从Firebase订购我的数据,所以最近的post是在顶部(如Instagram),但我不能让它正常工作。 我应该使用服务器时间戳吗? 有没有“createdAt”字段? func getPosts() { POST_REF.observeEventType(.Value, withBlock: { snapshot in guard let posts = snapshot.value as? [String : [String : String]] else { print("No Posts Found") return } Post.feed?.removeAll() for (postID, post) in posts { let newPost = Post.initWithPostID(postID, postDict: post)! Post.feed?.append(newPost) } Post.feed? = (Post.feed?.reverse())! self.tableView.reloadData() }, withCancelBlock: { error in print(error.localizedDescription) }) […]

如何从一个使用firebase设置的IOS应用程序读取/写入另一个Firebase项目中包含的另一个Firebase数据库? Swift 3

我有一个Firebase数据库连接到我的iOS应用程序与GoogleService-Info.plist。 在AppDelegate中,我configuration了应用FIRApp.configure()。 我可以读/写数据。 现在,从这个IOS应用程序,我想访问另一个FireBase数据库brevCustomer 。 出于某种原因, let dbRef来自viewDidLoad let dbRef在Xcode中有一个标志,说这个“不可变的值dbRef从来没有使用过”,而应用程序在有趣的startObserving() dbRef.observe(.value, with: { (snapshot: FIRDataSnapshot) in 。 任何人都可以展示如何进行configuration,以便我可以读取/写入到brevCustomer数据库? 编辑 请考虑以下情况: 我有两个IOS应用程序客户和工作人员,以及两个名为CustomerFireBase和WorkerFirebase的 Firebase项目,我希望他们以下面的方式工作。 客户使用电子邮件和密码注册,login,预订,数据保存在CustomerFireBase中。 工作者注册电子邮件和密码,日志是,观察WorkerFirebase的价值改变或添加子 从CustomerFireBase读取 写给CustomerFireBase 写给WorkerFirebase 我怎样才能做到这一点? 基本上,我需要从一个通过Firebaseconfiguration的IOS应用程序读取/写入访问到另一个Firebase项目中包含的另一个Firebase数据库。 Class Claim { var dbRef:FIRDatabaseReference! //create a reference to Firebase database `brevCustomer`, not the one from .plist file override func viewDidLoad() { super.viewDidLoad() let app = […]

Xcode 8.1推送通知在swift 2.3与firebase集成没有得到?

我正在与Xcode 8.1和Swift 2.3在这里我正在使用Firebase集成获取推送通知。我不知道为什么我没有得到通知..我的代码: func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { if #available(iOS 10.0, *) { let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound] UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions( authOptions, completionHandler: {_,_ in }) // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.currentNotificationCenter().delegate = self // For iOS 10 data message (sent via FCM) FIRMessaging.messaging().remoteMessageDelegate = […]

FCM – 以编程方式向用户段发送推送通知

我可以将通知从Firebase控制台发送到单个设备,主题和用户细分。 我想将推送通知发送给用户段。 我search了很多,但我只是得到脚本发送通知给单个用户或主题,而不是用户段。 我试了下面的代码 var client = new RestClient("https://fcm.googleapis.com/fcm/send"); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddHeader("authorization", "key=mykey"); request.AddParameter("application/json", "\n\n{\"to\" : \"user-segment-name\",\n\"notification\" : {\n \"body\" : \"test message\",\n \"title\" : \"Portugal vs. Denmark\"\n },\n \"priority\":\"high\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); Response.Write(response.Content); 我正在得到下面的回应 {"multicast_id":5837227475989925972,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Firebase聊天推送通知

我正在开发一个使用Firebase作为后端的聊天应用程序。 要求在每一个新的消息接收者得到一个推送通知,说他得到了一个新的消息。 这是我第一次做这样的事情,所以我有一个问题: 由于我们没有使用我们自己的服务器,我们是否需要第三方提供者(例如批处理)来处理推送通知? 如果我没有弄错,我想Firebase不支持发送像这样的推送通知,但只支持从控制台发送的通知。 任何帮助将是伟大的。

FCM后台通知无法在iOS中使用

我在iOS上遇到FCM通知问题。 当我的应用程序处于前台( appdelegate中的appdelegate被触发)时,我收到了成功的通知,但是当应用程序处于后台(我没有在iOS的通知托盘中看到任何内容)时,我没有收到通知。 所以我觉得问题是FCM发出的信息格式。 我的服务器发送给FCM的json格式如下: { "data":{ "title":"mytitle", "body":"mybody", "url":"myurl" }, "notification":{ "title":"mytitle", "body":"mybody" }, "to":"/topics/topic" } 正如你所看到的,在我的json中有两个块:一个通知块(在后台接收通知)和一个数据块(在前台接收通知)。 我不明白为什么后台通知没有收到。 我怀疑是关于块的顺序(如果我把“数据”块放在“通知”块之前,是一个问题?)。 编辑:关于这个问题的更多信息。 这是我的appdelegate.swift: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? // Application started func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { let pushNotificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) […]

Swift:在返回函数之前等待Firebase加载

我从firebase有一个简单的函数加载date。 func loadFromFireBase() -> Array<Song>? { var songArray:Array<Song> = [] ref.observe(.value, with: { snapshot in //Load songArray }) if songArray.isEmpty { return nil } return songArray } 目前这个函数总是返回零,即使有数据要加载。 它是这样做的,因为它不会在函数返回之前加载数组的地方执行完成块。 我正在寻找一种方法来使函数只返回一旦完成块已被调用,但我不能把回报完成块。

是否可以使用Firebase云消息传递(FCM)直接从设备发送PushNotifications到特殊的UDID?

我想在数据库中保留所有注册ID(推令牌),并从iPhone发送通知给用户。 我尝试了这样的事情,但没有得到任何通知。 func sendPNMessage() { FIRMessaging.messaging().sendMessage( ["body": "hey"], to: TOKEN_ID, withMessageID: "1", timeToLive: 108) } 我做错了什么,或者根本不可能呢?