xmppframework's didReceive presence is not working properly
I am using func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
for managing online offline status.This function is working fine for one to one user but it will not working properly on multiple user.
for example I have 3 user A, B and C now the scenario is Online offline status is working fine for A to B and B to A as func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
function is calling very well. but If C user check status of A or B then func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
is not being called.
I won't be able to understand what is the issue. Here is my Code:
func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) {
let presenceType = presence.type
let myUsername = sender.myJID?.user
print("myusername (myUsername)")
if let usr = presence.from?.user {
print("didReceive :- (presenceType)")
print("didReceive usr :- (usr)")
if usr != myUsername {
if presenceType == "available" {
let dict: NSDictionary = ["presenceType":"1",
"user_id":usr]
if !APP_DELEGATE.arrPresentUser.contains(dict) {
APP_DELEGATE.arrPresentUser.add(dict)
}
} else {
let pred : NSPredicate = NSPredicate(format: "user_id = %@", usr)
let approvalRequestArray = APP_DELEGATE.arrPresentUser.filtered(using: pred) as NSArray
if approvalRequestArray.count > 0 {
let dict = approvalRequestArray.object(at: 0) as! NSDictionary
APP_DELEGATE.arrPresentUser.remove(dict)
}
}
NotificationCenter.default.post(name: Notification.Name("ReceivedUserStatus"), object: nil)
}
}
}
Note: I had tried to use @objc also.(@objc func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
)
swift offline xmppframework
add a comment |
I am using func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
for managing online offline status.This function is working fine for one to one user but it will not working properly on multiple user.
for example I have 3 user A, B and C now the scenario is Online offline status is working fine for A to B and B to A as func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
function is calling very well. but If C user check status of A or B then func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
is not being called.
I won't be able to understand what is the issue. Here is my Code:
func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) {
let presenceType = presence.type
let myUsername = sender.myJID?.user
print("myusername (myUsername)")
if let usr = presence.from?.user {
print("didReceive :- (presenceType)")
print("didReceive usr :- (usr)")
if usr != myUsername {
if presenceType == "available" {
let dict: NSDictionary = ["presenceType":"1",
"user_id":usr]
if !APP_DELEGATE.arrPresentUser.contains(dict) {
APP_DELEGATE.arrPresentUser.add(dict)
}
} else {
let pred : NSPredicate = NSPredicate(format: "user_id = %@", usr)
let approvalRequestArray = APP_DELEGATE.arrPresentUser.filtered(using: pred) as NSArray
if approvalRequestArray.count > 0 {
let dict = approvalRequestArray.object(at: 0) as! NSDictionary
APP_DELEGATE.arrPresentUser.remove(dict)
}
}
NotificationCenter.default.post(name: Notification.Name("ReceivedUserStatus"), object: nil)
}
}
}
Note: I had tried to use @objc also.(@objc func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
)
swift offline xmppframework
add a comment |
I am using func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
for managing online offline status.This function is working fine for one to one user but it will not working properly on multiple user.
for example I have 3 user A, B and C now the scenario is Online offline status is working fine for A to B and B to A as func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
function is calling very well. but If C user check status of A or B then func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
is not being called.
I won't be able to understand what is the issue. Here is my Code:
func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) {
let presenceType = presence.type
let myUsername = sender.myJID?.user
print("myusername (myUsername)")
if let usr = presence.from?.user {
print("didReceive :- (presenceType)")
print("didReceive usr :- (usr)")
if usr != myUsername {
if presenceType == "available" {
let dict: NSDictionary = ["presenceType":"1",
"user_id":usr]
if !APP_DELEGATE.arrPresentUser.contains(dict) {
APP_DELEGATE.arrPresentUser.add(dict)
}
} else {
let pred : NSPredicate = NSPredicate(format: "user_id = %@", usr)
let approvalRequestArray = APP_DELEGATE.arrPresentUser.filtered(using: pred) as NSArray
if approvalRequestArray.count > 0 {
let dict = approvalRequestArray.object(at: 0) as! NSDictionary
APP_DELEGATE.arrPresentUser.remove(dict)
}
}
NotificationCenter.default.post(name: Notification.Name("ReceivedUserStatus"), object: nil)
}
}
}
Note: I had tried to use @objc also.(@objc func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
)
swift offline xmppframework
I am using func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
for managing online offline status.This function is working fine for one to one user but it will not working properly on multiple user.
for example I have 3 user A, B and C now the scenario is Online offline status is working fine for A to B and B to A as func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
function is calling very well. but If C user check status of A or B then func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
is not being called.
I won't be able to understand what is the issue. Here is my Code:
func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence) {
let presenceType = presence.type
let myUsername = sender.myJID?.user
print("myusername (myUsername)")
if let usr = presence.from?.user {
print("didReceive :- (presenceType)")
print("didReceive usr :- (usr)")
if usr != myUsername {
if presenceType == "available" {
let dict: NSDictionary = ["presenceType":"1",
"user_id":usr]
if !APP_DELEGATE.arrPresentUser.contains(dict) {
APP_DELEGATE.arrPresentUser.add(dict)
}
} else {
let pred : NSPredicate = NSPredicate(format: "user_id = %@", usr)
let approvalRequestArray = APP_DELEGATE.arrPresentUser.filtered(using: pred) as NSArray
if approvalRequestArray.count > 0 {
let dict = approvalRequestArray.object(at: 0) as! NSDictionary
APP_DELEGATE.arrPresentUser.remove(dict)
}
}
NotificationCenter.default.post(name: Notification.Name("ReceivedUserStatus"), object: nil)
}
}
}
Note: I had tried to use @objc also.(@objc func xmppStream(_ sender: XMPPStream, didReceive presence: XMPPPresence)
)
swift offline xmppframework
swift offline xmppframework
asked Nov 27 '18 at 11:15
KhushKhush
1319
1319
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
If you want to check presence of particular user, use this.
let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)
Get the presence in delegate method.
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
add a comment |
I have solved my problem by adding following code
let userReceiverJID = XMPPJID(string: "(receiverJID)@(CHATHOST)")
APP_DELEGATE.xmppRoster.acceptPresenceSubscriptionRequest(from: userReceiverJID!, andAddToRoster: true)
APP_DELEGATE.xmppRoster.subscribePresence(toUser: userReceiverJID!)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498461%2fxmppframeworks-didreceive-presence-is-not-working-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to check presence of particular user, use this.
let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)
Get the presence in delegate method.
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
add a comment |
If you want to check presence of particular user, use this.
let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)
Get the presence in delegate method.
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
add a comment |
If you want to check presence of particular user, use this.
let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)
Get the presence in delegate method.
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}
If you want to check presence of particular user, use this.
let query = XMLElement(name: "query", xmlns: "jabber:iq:last")
let iq = XMPPIQ(type: "get", to: "User's JID here", elementID: xmppStream.generateUUID, child: query)
self.xmppStream.send(iq)
Get the presence in delegate method.
func xmppStream(_ sender: XMPPStream, didReceive iq: XMPPIQ) -> Bool {
if iq.isResultIQ {
print(iq.from?.user)
print(iq.lastActivitySeconds())
}
}
answered Nov 27 '18 at 12:26
Fenny RoyFenny Roy
1266
1266
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
add a comment |
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
Can you please tell me that what is xmppStream.generateUUID
– Khush
Nov 28 '18 at 6:49
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
@KD4, It is a method that XMPP provides and it generates a UUID and returns as a string. It is like unique id to identify some tag or attribute. You can use any other string also instead of this.
– Fenny Roy
Nov 28 '18 at 7:11
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
I am getting following error : <query xmlns="jabber:iq:last"></query>, <error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"></forbidden></error>
– Khush
Nov 28 '18 at 8:25
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
This seems to be some kind of authentication error. Check your configuration and Rights. Also check if you are passing the full jid or not? Like userid@xmpp.something.in. If not, try to pass the full JID.
– Fenny Roy
Nov 28 '18 at 12:26
add a comment |
I have solved my problem by adding following code
let userReceiverJID = XMPPJID(string: "(receiverJID)@(CHATHOST)")
APP_DELEGATE.xmppRoster.acceptPresenceSubscriptionRequest(from: userReceiverJID!, andAddToRoster: true)
APP_DELEGATE.xmppRoster.subscribePresence(toUser: userReceiverJID!)
add a comment |
I have solved my problem by adding following code
let userReceiverJID = XMPPJID(string: "(receiverJID)@(CHATHOST)")
APP_DELEGATE.xmppRoster.acceptPresenceSubscriptionRequest(from: userReceiverJID!, andAddToRoster: true)
APP_DELEGATE.xmppRoster.subscribePresence(toUser: userReceiverJID!)
add a comment |
I have solved my problem by adding following code
let userReceiverJID = XMPPJID(string: "(receiverJID)@(CHATHOST)")
APP_DELEGATE.xmppRoster.acceptPresenceSubscriptionRequest(from: userReceiverJID!, andAddToRoster: true)
APP_DELEGATE.xmppRoster.subscribePresence(toUser: userReceiverJID!)
I have solved my problem by adding following code
let userReceiverJID = XMPPJID(string: "(receiverJID)@(CHATHOST)")
APP_DELEGATE.xmppRoster.acceptPresenceSubscriptionRequest(from: userReceiverJID!, andAddToRoster: true)
APP_DELEGATE.xmppRoster.subscribePresence(toUser: userReceiverJID!)
answered Nov 29 '18 at 4:05
KhushKhush
1319
1319
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498461%2fxmppframeworks-didreceive-presence-is-not-working-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown