我正在使用JSQMessagesViewController在我的應用程序中實現聊天。我希望能夠向用戶發送我正在與我的位置聊天。這就是我所做的。使用JSQLocationMediaItem發送位置
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.latestLocation = locations[locations.count-1]
}
let sendLocation = UIAlertAction(title: "Send Location", style: .default, handler: { (action) -> Void in
let loc: JSQLocationMediaItem = JSQLocationMediaItem(location: self.latestLocation)
loc.appliesMediaViewMaskAsOutgoing = true
let locmessage: JSQMessage = JSQMessage(senderId: self.senderId, senderDisplayName: self.senderDisplayName, date: NSDate() as Date!, media: loc)
self.messages.append(locmessage)
self.finishSendingMessage(animated: true)
self.collectionView.reloadData()
print("Location button tapped")
})
let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in
print("Cancel button tapped")
})
alertController.addAction(sendLocation)
self.navigationController!.present(alertController, animated: true, completion: nil)
但是,當我點擊發送位置按鈕,我只是得到一個圖像氣泡與紡車,它永遠做。
嘿我試圖使用這段代碼,但確切的是:self.latestLocation = locations [locations.count-1]你能解釋它嗎? –