Is there anyway access to the subscribed Firebase themes?

I'm currently trying to port the application to firebase, and I'm looking for the Firebase equivalent for Parse Installations and Channels.

What I found is that we should use themes, however, in my application, “subscribing” and “unsubscribing” to topics are common, but there is no way (which I found) to find out which topics the user has subscribed to . Any ideas?

I looked through the Firebase documentation, but I'm new to Firebase, so maybe someone with more experience will find out: https://firebase.google.com/docs/cloud-messaging/android/topic-messaging#managing_topic_subscriptions_from_the_server

Thanks in advance for your help!

+3
source share
2 answers

Subscriptions for FCM topics are based on the instance ID of the application, so when you subscribe or unsubscribe to or from a topic, the IID is used.

You can use the instance API to get information about a specific IID, this information includes topics that the IID is currently subscribing to. See reference

+1
source

You need to access the instance API. I created an extension

https://gist.github.com/eduardo22i/0ee8960c36659b17fbc538964e929cac

Message extension {

static private let accessToken = "" //Server Web Key struct Topic : Decodable { var name : String? var addDate : String? } struct Rel : Decodable { var topics = [Topic]() init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) let relContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .rel) let topicsContainer = try relContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: .topics ) for key in topicsContainer.allKeys { var topic = Topic() topic.name = key.stringValue let topicContainer = try? topicsContainer.nestedContainer(keyedBy: CodingKeys.self, forKey: key) topic.addDate = try! topicContainer?.decode(String.self, forKey: .addDate) self.topics.append(topic) } } struct CodingKeys : CodingKey { var stringValue: String init?(stringValue: String) { self.stringValue = stringValue } var intValue: Int? { return nil } init?(intValue: Int) { return nil } static let rel = CodingKeys(stringValue: "rel")! static let topics = CodingKeys(stringValue: "topics")! static let addDate = CodingKeys(stringValue: "addDate")! } } func loadTopics(block : @escaping (_ topics: [Messaging.Topic]?, _ error: Error?) -> Void ) { if let token = InstanceID.instanceID().token() { let url = URL(string: "https://iid.googleapis.com/iid/info/\(token)?details=true")! var request = URLRequest(url: url) request.addValue("key=\(Messaging.accessToken)", forHTTPHeaderField: "Authorization") let dataTask = URLSession.shared.dataTask(with: request) { (data, response, error) in DataManager.shared.make(request: urlRequest, block: { (data, error) in if let data = data { let decoder = JSONDecoder() let rel = try? decoder.decode(Rel.self, from: data) block(rel?.topics, error) } else { block(nil, error) } } dataTask.resume() } } } // Usage Messaging.messaging().loadTopics { (topics, error) in topics?.forEach({ (topic) in print(topic.name) }) } 
0
source

Source: https://habr.com/ru/post/1260474/


All Articles