processone / xmpp-messenger-ios

iOS XMPP Messenger Framework
MIT License
219 stars 93 forks source link

How to create send and receive media / photo #51

Closed Koutenshidatshu closed 8 years ago

Koutenshidatshu commented 8 years ago

Hi, i want to ask how to send message image from photo gallery in swift?

here is the function after select photo and then sending the image

    func  imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { 
    var image : UIImage
    image = (info[UIImagePickerControllerOriginalImage] as? UIImage)!
    var photoItem = JSQPhotoMediaItem()
    photoItem.image = image

    let fullMessage = JSQMessage(senderId: OneChat.sharedInstance.xmppStream?.myJID.bare(), senderDisplayName: OneChat.sharedInstance.xmppStream?.myJID.bare(), date: NSDate(), media: photoItem)
    messages.addObject(fullMessage)
    let mediaItem:JSQMessageMediaData = fullMessage!.media
        photoItem = mediaItem as! JSQPhotoMediaItem

    if (mediaItem.isKindOfClass(JSQPhotoMediaItem)) {

        if let recipient = recipient {

            OneMessage.sendMessage("image", to: recipient.jidStr, completionHandler: { (stream, image) -> Void in
                JSQSystemSoundPlayer.jsq_playMessageSentSound()
                self.finishSendingMessageAnimated(true)
            })
        }
    }
    self.dismissViewControllerAnimated(true, completion: nil)
}`
Koutenshidatshu commented 8 years ago

` func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
var image : UIImage image = (info[UIImagePickerControllerOriginalImage] as? UIImage)! var photoItem = JSQPhotoMediaItem() photoItem.image = image

    let fullMessage = JSQMessage(senderId: OneChat.sharedInstance.xmppStream?.myJID.bare(), senderDisplayName: OneChat.sharedInstance.xmppStream?.myJID.bare(), date: NSDate(), media: photoItem)
    messages.addObject(fullMessage)
    let mediaItem:JSQMessageMediaData = fullMessage!.media
        photoItem = mediaItem as! JSQPhotoMediaItem

    if (mediaItem.isKindOfClass(JSQPhotoMediaItem)) {

        if let recipient = recipient {                
            OneMessage.sendMessage("image", to: recipient.jidStr, completionHandler: { (stream, image) -> Void in
                JSQSystemSoundPlayer.jsq_playMessageSentSound()
                self.finishSendingMessageAnimated(true)
            })
        }
    }
    self.dismissViewControllerAnimated(true, completion: nil)
}  `
baoluo commented 8 years ago

Hello @Koutenshidatshu I don't understand the problem here, this is not an issue at all, you should ask this kind of question on StackOverflow. Closing this now