robbiehanson / XMPPFramework

An XMPP Framework in Objective-C for Mac and iOS
Other
5.91k stars 2.09k forks source link

XMPPRosterCoreDataStorage's MOC doesn't gives Roster list for Newly registered user #379

Open saru2020 opened 10 years ago

saru2020 commented 10 years ago

Hi,

[XMPPRosterCoreDataStorage mainThreadManagedObjectContext] doesn't list the Roster list, when i login by creating/registering a new user, whereas it lists all the rosters/buddies when i quit & restart the app.

Also, if i login using an already registered user, it clearly fetches the roster list and works as expected.

I tried re-initializing the fetchedResultsController after getting a callback from "- (void)xmppRosterDidEndPopulating:(XMPPRoster *)sender" delegate, but no luck.

Would be great, if i get any help.

saru2020 commented 10 years ago

Here's what i am doing: (i) After successful Registration of User A, i send add buddy request to all the contacts in User A's device, (only to those who are all registered in my server). (ii) User A is added immediately in other users contacts/roster list (Since, we have auto accept buddy request approach), to whom the buddy request was sent. (iii) In User A's device, immediately after sending buddy requests, i do this: fetchedResultsController = nil; [tableview reloadData];

But, the roster list shows 0 contacts. Actually it seems like those contacts are added, since I am able to get user presence info whenever anyone in my roster list goes online/offline.

I think it is a problem with Core Data manipulation and i am doing something wrong with it, since i am a noob in that.

Can anyone help me with this problem?

ObjColumnist commented 10 years ago

NSFetchedResultsController is notoriously buggy, sounds like you are having the same issue as in #366

I would performFetch: on your NSFetchedResultsController in xmppRosterDidEndPopulating: and xmppRoster:didReceiveRosterPush: to see if it solves your issue.

You could also executeFetchRequest:error directly on the mainThreadManagedObjectContext to see if the users are in there.

saru2020 commented 10 years ago

Hi,

Thanks for giving out a bunch of options, but i have already tried them all, but had no luck in getting it work.

It happens only for the Newly Registered users.

Is there anything special need to be done when fetching Roster list initially or Adding Buddies to the Roster list initially?

ObjColumnist commented 10 years ago

No it should work the same as always, obviously there will be nothing in the roster for xmppRosterDidEndPopulating but every time a new roster item is added you should get a roster push xmppRoster:didReceiveRosterPush:

saru2020 commented 10 years ago

I just tried debugging the Core Data Sqlite by adding : "-com.apple.CoreData.SQLDebug 1" to argument in Run Scheme. I don't see users been added in the debug console just at the first time when coming in by registering a new user.

Still i can see it in UI, if the Sqlite file isn't locked up. Is there any way to unlock this file? XMPPRoster.sqlite which is placed under: ~/Library/Application Support/iPhone Simulator/[SDK version]/Applications/[App GUID]/Documents

Or is there any other ways to look up the into the database file for any entries into the "ZXMPPUSERCOREDATASTORAGEOBJECT" table??

saru2020 commented 10 years ago

After Several Hours of Debugging, Finally, i have found the bug.

I was Registering an User with a XMPPStream object say registerStream, but i was connecting to the XMPP server by creating an another instance of the same XMPPStream object(registerStream), which was the cause of the issue.

But still I am not very clear on the issue(Tired of debugging), really interested to know the actual reason behind it, if anyone could explain it clearly or else i'll have to find it out some time later.

ObjColumnist commented 10 years ago

Is it just a simple case of XMPPRoster not being activated on the new XMPPStream?

saru2020 commented 10 years ago

No. I am doing the same stuff with both the type of object creation. Not sure what it would be. No clues yet.