processone / xmpp-messenger-ios

iOS XMPP Messenger Framework
MIT License
219 stars 93 forks source link

getting user nil from xmppRosterStorage #40

Closed anuragbisht closed 8 years ago

anuragbisht commented 8 years ago

Hi I am new to XMPP i followed all the steps told. I am able to send messages successfully but when i receive any message the app crashes with error

fatal error: unexpectedly found nil while unwrapping an Optional value

so i started using breakpoints and found that the value of user is nil in OneMessage.swift

    public func xmppStream(sender: XMPPStream, didReceiveMessage message: XMPPMessage) {
        print("sender")
        print(message.to())
        print("message")
        print(message)
        // user is nil after this line 
        let user = OneChat.sharedInstance.xmppRosterStorage.userForJID(message.from(), xmppStream: OneChat.sharedInstance.xmppStream, managedObjectContext: OneRoster.sharedInstance.managedObjectContext_roster())

        if !OneChats.knownUserForJid(jidStr: "ankit") {
            OneChats.addUserToChatList(jidStr: "ankit")
        }

        if message.isChatMessageWithBody() {
            OneMessage.sharedInstance.delegate?.oneStream(sender, didReceiveMessage: message, from: user)

        } else {
            //was composing
            if let _ = message.elementForName("composing") {
            //  OneMessage.sharedInstance.delegate?.oneStream(sender, userIsComposing: user)
            }
        }
    }

please help me

arunarya111 commented 8 years ago

i am also facing the same issue

baoluo commented 8 years ago

@anuragbisht @arunarya111 Hello to both of you, if the roster is nil, you should check the configuration, you may have a bad / failed init, resulting in a 'nil' roster

arunarya111 commented 8 years ago

can you please suggest how to configure? I have followed all the steps in the tutorial

aitbaali commented 8 years ago

same issue, any solution please? Server: Openfire 4.0.1 Swift: 2.2 Xcode: 7.3

aitbaali commented 8 years ago

@ObjColumnist any solution?

pka23 commented 8 years ago

user == nil when your two jabber accounts not subscribed each other. i had to subscribe accounts in desktop IM client (such as Adium) before it works

MrPradip commented 8 years ago

I am also facing the same issue. please send the configuration setting .. @baoluo

chetansrm commented 8 years ago

When I was new on XMPP I was also facing the same issue after searching a lot I got nothing but #baoluo suggests me to to create an object of xmppRosterStorage. Definitely you are facing this problem because you are calling a function of xmppRosterStorage without initializing it.So firstly create an object of xmppRosterStorage then call any of the function with it. I hope it will help you.

MrPradip commented 8 years ago

where should I create object. for example I am trying to create a group using separate class in swift . Its creating and after crashing its automatically being deleted. when i got the nil value in user.. @chetansrm

MrPradip commented 8 years ago

I have checked its already initialized as "var xmppRosterStorage = XMPPRosterCoreDataStorage()" in onechat.swift... And i am using "OneChat.sharedInstance.xmppRosterStorage". so it should work. Help me out my friend. I am new to xmpp @chetansrm

javedsiddique943 commented 6 years ago

I m also facing same issue

let user = OneChat.sharedInstance.xmppRosterStorage.user(for: message.from, xmppStream: OneChat.sharedInstance.xmppStream, managedObjectContext: OneRoster.sharedInstance.managedObjectContext_roster()) user is nil how to solve this. Please help as soon as possible

javedsiddique943 commented 6 years ago

from ejabberd admin panel you need to subscribe both the user by selecting the user then selecting roaster then adding the another user then you can send and recieve the message between two user Issue is resolved. Thanks close this issue.