I don't really understand when messageLostHandler is triggered on the subscriptionWithMessageFoundHandler method.
This is my code:
func suscribeToNearbyDevices(myUserId: String){
subscription = messageMgr?.subscription(messageFoundHandler: { (message: GNSMessage?) in
if let incomingMessage = message, let content = incomingMessage.content {
if let userIdEncoded = String(data: content, encoding: String.Encoding.utf8) {
NotificationCenter.default.post(name: Notification.Name(rawValue: CommunicationVariables.newUserNotificationKey), object: nil,
userInfo:userIdEncoded)
}}, messageLostHandler: { (message: GNSMessage?) in
if let incomingMessage = message, let content = incomingMessage.content {
if let userIdEncoded = String(data: content, encoding: String.Encoding.utf8) {
NotificationCenter.default.post(name: Notification.Name(rawValue: CommunicationVariables.exitUserNotificationKey), object: nil,
userInfo: [CommunicationVariables.userIdNotificationField:userIdEncoded])
}
}
}, paramsBlock:{(params:GNSSubscriptionParams?) in
guard let params = params else { return }
params.strategy = GNSStrategy(paramsBlock: { (params: GNSStrategyParams?) in
guard let params = params else { return }
params.allowInBackground = true
})
})
}
I have two iphones, If I have the two apps on the foreground, they can see each other. When I press home in one, the messageLostHandler is triggered, but if I walk out of range (like outside-of-the-house-out-of-range) the messageLostHandler is never triggered.
Why? What cause the messageLostHandler to be triggered?
Thanks!