gpt4 book ai didi

ios - 使用 JSQLocationMediaItem 发送位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:22:40 25 4
gpt4 key购买 nike

我正在使用 JSQMessagesViewController 在我的应用程序中实现聊天。我希望能够向用户发送我正在与我的位置聊天的信息。这就是我所做的。

    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)

但是,当我点击发送位置按钮时,我只会看到一个带有旋转轮的图像气泡,并且它会一直持续下去。 enter image description here

最佳答案

在您的代码中添加解决方案

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()
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)

您必须在完成位置对象创建后设置位置。

关于ios - 使用 JSQLocationMediaItem 发送位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46080206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com