Couchbase Lite

39 views
Skip to first unread message

parvez....@decurtis.com

unread,
Mar 18, 2017, 11:28:20 AM3/18/17
to Couchbase Mobile


Recently, I started exploring couchbase lite mobile sdk for iOS. The sync server and gateway are also up and running. I am going through the couch chat sample. There are few questions:

1. I am checking the basic authentication (CBLAuthentication). What is the correct way to check authentication success ? Do we have to rely on the status of push / pull replication as reported in the notification corresponding to replication progress ? If Yes then which status should be used for this ? If No then what is the other way to do this ?
2. I am trying to create a simple chat application in iOS swift whose data model resembles that of couchchat. The database setup is also successful. The replication is also accomplished. The chat room model is as below:
public class ChatRoom: CBLModel{
    @NSManaged var title: String!
    @NSManaged var channel_id: String!
    @NSManaged var owners: [String]!
    @NSManaged var members: [String]!
}
Is above model structure correct ?
Then I tried to create a chatroom based on loggedInusername & another user name as in the function
public func chatRoom(forUser aUserName: String)->ChatRoom?{
        let chatRoomTitleToMatch = loggedInUserName + "_" + aUserName
        var chatRoom: ChatRoom? = nil
//myChatRoomsQuery is also created prior to its use here
if let existingChatRooms = myChatRoomsQuery?.rows{ while let aRow = existingChatRooms.nextRow() { let existingRoom = ChatRoom(for: aRow.document!) if (existingRoom?.owners.contains(loggedInUserName)) == true || (existingRoom?.owners.contains(aUserName)) == true{ chatRoom = existingRoom break } } } if chatRoom == nil { let aNewChatRoom = ChatRoom(forNewDocumentIn: self.database!) aNewChatRoom.title = chatRoomTitleToMatch aNewChatRoom.owners = [loggedInUserName,aUserName] aNewChatRoom.members = aNewChatRoom.owners aNewChatRoom.channel_id = aNewChatRoom.document?.documentID aNewChatRoom.type = "room" do{ try aNewChatRoom.save() }catch{ print("Encountered error: \(error) while saving chat room.") } chatRoom = aNewChatRoom } return chatRoom }
But the room is not getting saved. Also there is no error returned in the save operation. What can be the probable issue ? The application has successfully connected to the database & push / pull replication has also occured.
I have also registered the above model class (ChatRoom) as below:
fileprivate func registerModelClasses(){
        self.database?.modelFactory?.registerClass("UserProfile", forDocumentType: "profile")
        self.database?.modelFactory?.registerClass("ChatRoom", forDocumentType: "room")
}

pa...@couchbase.com

unread,
Mar 20, 2017, 2:16:43 PM3/20/17
to Couchbase Mobile
Can you enable 'Database' and 'Model' logging as below and see if there are any log messages printed out?

CBLManager.enableLogging("Database")
CBLManager.enableLogging("Model")

Jens Alfke

unread,
Mar 21, 2017, 12:39:40 AM3/21/17
to mobile-c...@googlegroups.com

> On Mar 17, 2017, at 11:29 PM, parvez....@decurtis.com wrote:
>
> But the room is not getting saved.

How do you know it’s not being saved? What is the code that fails because the document isn’t saved?

—Jens

Reply all
Reply to author
Forward
0 new messages