iOS XMMPFramework-有时XMPPUserCoreDataStorageObject为nil

时间:2018-12-12 11:25:14

标签: ios core-data xmppframework

我一直缺少联系人列表(xmppRoster),我注意到当我尝试断点/调试对象XMPPUserCoreDataStorageObject时发现nil。只要有nil值,只要查看我的代码,该条件就不会执行,并进入“ [不可用]”。

我拒绝接受此消息,因为当缺少联系人列表和组/用户名出现[不可用]时,这对于用户来说是糟糕的用户体验。有时可能是在空闲时间或在后台状态。

let contact =  appDelegate.xmppRosterStorage.user(for: userJID, xmppStream: appDelegate.xmppStream, managedObjectContext: appDelegate.managedObjectContext_roster())

if contact?.nickname != nil {
    self.navigationItem.titleView = self.setTitle(title: (contact?.nickname)! , subtitle: "Tap to view group details")
} 
else {
    if(appDelegate.xmppRoom.roomJID.user.contains("----")) {
        self.navigationItem.title = (appDelegate.xmppRoom.roomJID.user.components(separatedBy: ".")[1])+"@---"
    } 
    else {
        if(tempGroupTitle != nil) {
            self.navigationItem.titleView = self.setTitle(title: tempGroupTitle , subtitle: "Tap to view group details")
        }
        else {
            let naString = "[Not Available]"
            self.navigationItem.titleView = self.setTitle(title: naString , subtitle: "Tap to view group details")
        }
    }
}

我尝试使用try catch块

if contact == nil {
    do {
        try! fetchedResultsController.performFetch()
    } 
    catch {
        // print(error.localizedDescription)
    }
}

但是它似乎不起作用。希望有人可以帮我这个忙。谢谢!

0 个答案:

没有答案