ios - 使用 JSQLLocationMediaItem 发送位置
<p><p>我正在使用 JSQMessagesViewController 在我的应用程序中实现聊天。我希望能够向用户发送我正在与我的位置聊天的用户。这就是我所做的。</p>
<pre><code> func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: ) {
self.latestLocation = locations
}
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)
</code></pre>
<p>但是当我点击发送位置按钮时,我只是得到一个带有旋转轮的图像气泡,并且它永远存在。
<a href="/image/MN35f.png" rel="noreferrer noopener nofollow"><img src="/image/MN35f.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在代码中添加解决方案</p>
<pre><code>func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: ) {
self.latestLocation = locations
}
let sendLocation = UIAlertAction(title: "Send Location", style: .default, handler: { (action) -> Void in
let loc: JSQLocationMediaItem = JSQLocationMediaItem()
loc.setLocation(self.latestLocation) { // Added completion handler for updating the map after getting the location.
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)
</code></pre>
<p>您必须在完成位置对象创建后设置位置。</p></p>
<p style="font-size: 20px;">关于ios - 使用 JSQLLocationMediaItem 发送位置,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46080206/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46080206/
</a>
</p>
页:
[1]