-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
The library works perfectly when the app is in foreground. But if the app is pushed to background the messages sent are not thrower in the below function
_ = commHub.on(eventName: "GetMessage") { (args) in
if let msgID = args[0] as? String, let message = args[1] as? String {
print("SignalR \(msgID): \(message)")
}
}
instead the messages are received in a single shot once the app is opened.
Say if i have to receive a,b and b,c while the app is in background it is not instead i think it is keeping in stack and throwing to the receiver once the application is opened i.e. the app is in foreground
Below is my connect and disconnect code which is added in the AppDelegate.swift
var commHub: HubProxy!
var connection: HubConnection!
var commEstablished = false
func commConnect()
{
if !commEstablished, Common.checkInternet(){
let qs = ["MsgID":"Tesing123"]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders
if #available(iOS 9.0, *) {
configuration.shouldUseExtendedBackgroundIdleMode = true
}
connection = HubConnection(withUrl: "http://192.168.0.100/ChatApplication/", queryString: qs, sessionManager: SessionManager(configuration: configuration))
commHub = self.connection.createHubProxy(hubName: "CommHub")
_ = commHub.on(eventName: "GetMessage") { (args) in
if let msgID = args[0] as? String, let message = args[1] as? String {
print("SignalR \(msgID): \(message)")
self.commHub.invoke(method: "UpdateMessage", withArgs: [msgID])
}
}
connection.started = {
self.commEstablished = true
print("SignalR Connected")
}
connection.reconnecting = {
print("Reconnecting...")
}
connection.reconnected = {
print("SignalR Reconnected")
}
connection.closed = {
self.commEstablished = false
print("SignalR Disconnected")
}
connection.connectionSlow = {
print("SignalR Connection slow...")
}
connection.error = { [unowned self] error in
let anError = error as NSError
print("SignalR Error \(error)")
if anError.code == NSURLErrorTimedOut {
self.connection.start()
}
}
connection.start()
}else{
self.commEstablished = false
}
}
func commDisconnect()
{
if connection != nil {
connection.disconnect()
}
self.commEstablished = false
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels