Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用JSQLocationMediaItem发送位置_Ios_Cllocationmanager_Jsqmessagesviewcontroller - Fatal编程技术网

Ios 使用JSQLocationMediaItem发送位置

Ios 使用JSQLocationMediaItem发送位置,ios,cllocationmanager,jsqmessagesviewcontroller,Ios,Cllocationmanager,Jsqmessagesviewcontroller,我正在使用JSQMessagesViewController在我的应用程序中实现聊天。我想能够发送用户,我正在与我的位置聊天。这就是我所做的 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { self.latestLocation = locations[locations.count-1] } let sendL

我正在使用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)
但当我点击“发送位置”按钮时,我得到的只是一个带有旋转轮子的图像气泡,它会永远持续。
在代码中添加解决方案

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)

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

嘿,我正在尝试使用此代码,但具体是什么:self.latestLocation=locations[locations.count-1]您能解释一下吗?@GhiggzPikkoro self.latestLocation=locations[locations.count-1]用于从CLLocationManager委托方法中拾取最后一个位置。好的,我用另一种方法进行了操作,它也可以工作,但我想问您是否知道当用户用地图点击气泡时,它如何在所有视图中显示地图?根据你的说法可能吗?你这么做了吗?嘿,我正试图使用这段代码,但那到底是什么:self.latestLocation=locations[locations.count-1]你能解释一下吗?