我正在socket.io快速的ios應用程序中實現。目前,在幾個面板上,我正在偵聽服務器并等待傳入消息。我這樣做是通過getChatMessage在每個面板中調用函數:func getChatMessage(){ SocketIOManager.sharedInstance.getChatMessage { (messageInfo) -> Void in dispatch_async(dispatch_get_main_queue(), { () -> Void in //do sth depending on which panel user is }) }}但是我注意到這是一個錯誤的方法,我需要更改它-現在我只想開始監聽一次傳入的消息,并且在出現任何消息時-將此消息傳遞給任何偵聽它的面板。所以我想通過NSNotificationCenter傳遞傳入的消息。到目前為止,我已經能夠傳遞發生某事的信息,但是無法傳遞數據本身。我這樣做的原因是:NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.showSpinningWheel(_:)), name: showSpinner, object: nil)然后我有一個函數叫做:func showSpinningWheel(notification: NSNotification) {}每當我想稱呼它時,我都在做:NSNotificationCenter.defaultCenter().postNotificationName(hideSpinner, object: self)那么如何傳遞對象messageInfo并將其包含在調用的函數中呢?
- 3 回答
- 0 關注
- 585 瀏覽
添加回答
舉報
0/150
提交
取消