-jio-start-block-type-2
-jio-style-title
import Foundation
import JioPushFramework
import Firebase
extension JPNRegistration {
func subscribeTo(topicName: String, appName: String) {
if !topicName.isEmpty && !appName.isEmpty {
let topic = "JP_\(appName.trimmed())_\(topicName.trimmed())-iOS"
Messaging.messaging().subscribe(toTopic: topic) { error in
if let _ = error {
print("Subscribe to \(topic) topic failed")
JPNRegistration
.shared
.delegate?
.onErrorResponse(errorCode: 404,
errorMessage: "Subscribing to \(topicName) Failed",
forRequest: .subscribe)
} else {
JPNRegistration
.shared
.subscribeToTopic(topicName: topicName,
appName: appName)
}
}
}
}
func unsubscribeTo(topicName: String, appName: String) {
if !topicName.isEmpty && !appName.isEmpty {
let topic = "JP_\(appName.trimmed())_\(topicName.trimmed())-iOS"
Messaging.messaging().unsubscribe(fromTopic: topic){ error in
if let _ = error {
JPNRegistration
.shared
.delegate?
.onErrorResponse(errorCode: 404,
errorMessage: "Unsubscribing to \(topicName) Failed",
forRequest: .unsubscribe)
} else {
print("Unsubscribe to \(topic) topic success")
JPNRegistration
.shared
.unsubscribeToTopic(topicName: topicName,
appName: appName)
}
}
}
}
}
extension String {
func trimmed() -> String {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
-jio-end-block-type-2