saving fetched XMPPframeWork vCards into CoreData in Swift4

只愿长相守 提交于 2019-12-11 15:15:42

问题


I was able to create and update a vCard using this code

    let xmppvCardStorage = XMPPvCardCoreDataStorage.sharedInstance()
    let xmppvCardTempModule = XMPPvCardTempModule.init(vCardStorage:xmppvCardStorage!)
    xmppvCardTempModule.activate(self.stream)
    xmppvCardTempModule.addDelegate(self, delegateQueue: DispatchQueue.main)
    let vCard = DDXMLElement(name: "vCard", xmlns: "vcard-temp")
    let vCardTemp = XMPPvCardTemp.vCardTemp(from: vCard)
    vCardTemp.nickname = "john"
    vCardTemp.jid = XMPPJID(string: "john123@www.example.com")

Also I was able to fetch that vCard using the following code:

    let xmppvCardStorage = XMPPvCardCoreDataStorage.sharedInstance()
    let xmppvCardTempModule = XMPPvCardTempModule.init(vCardStorage: xmppvCardStorage!)
    xmppvCardTempModule.activate(self.stream)
    let jID = XMPPJID(string: "john@www.example.com")
    xmppvCardTempModule.addDelegate(self,delegateQueue:DispatchQueue.main)
    xmppvCardTempModule.fetchvCardTemp(for: jID!, ignoreStorage:false)

As you can see I am fetching the vCard from my server. This is done by setting ignoreStorage to false

My question is does the XMPPFrameWork support a way to store the retrieved vCards in CoreData such that I don't have to retrieve it every time


回答1:


fetchvCardTemp simply fetches the vCardTemp for the given JID if it is not in the storage.when you set ignoreStorage to false you are saying that i don't want to use storage and i want to fetch it via the XMPPStream. you should use just xmppvCardStorage and one of it's function called vCardTempForJID and simply pass your favorite jID and it will return it to you



来源:https://stackoverflow.com/questions/51797335/saving-fetched-xmppframework-vcards-into-coredata-in-swift4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!