简体   繁体   English

在Swift4中将获取的XMPPframeWork vCard保存到CoreData中

[英]saving fetched XMPPframeWork vCards into CoreData in Swift4

I was able to create and update a vCard using this code 我可以使用此代码创建和更新vCard

    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: 另外,我还可以使用以下代码来获取该vCard:

    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. 如您所见,我正在从服务器中获取vCard。 This is done by setting ignoreStorage to false 这是通过将ignoreStorage设置为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 我的问题是XMPPFrameWork是否支持一种将检索到的vCard存储在CoreData中的方法,这样我就不必每次都检索它

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. fetchvCardTemp简单地获取了vCardTemp对于给定的JID如果它不是在你设定的storage.when ignoreStorage假你说的,我不希望使用存储,我想通过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 您应该只使用xmppvCardStorage及其功能之一,即vCardTempForJID然后简单地传递您喜欢的jID,它将其返回给您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM