I am using the JSQMessagesViewController in a Chat App I am making. I am able so successfully send and receive text messages but would like to add support for Images also.
I have implemented the didPressAccessoryButton function which is executed when the lower bottom paper clip / attachment button is clicked.
My question is - I am not sure what to do next? or how to implement the JSQPhotoMediaItem
(link)???
override func didPressAccessoryButton(sender: UIButton!) {
var imgToSend = UIImage(named: "devassets_avatar_01_selected.png")
var photoMediaItem = JSQPhotoMediaItem(image: imgToSend)
let mediaMsg = PFObject(className: "Message")
mediaMsg["content"] = "this is photo item"
mediaMsg["room"] = room
mediaMsg["user"] = PFUser.currentUser()
mediaMsg["media"] = photoMediaItem
mediaMsg.saveInBackgroundWithBlock { (success, error) -> Void in
if error == nil {
//self.loadMessages()
self.room["lastUpdate"] = NSDate()
self.room.saveInBackgroundWithBlock(nil)
}else{
println("error sending message \(error!.localizedDescription)")
}
}
self.finishSendingMessage()
}
When the above function is run, the app crashes with the following stacktrace:
2015-06-24 09:58:33.850 ShitTalk[9530:818302] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'PFObject values may not have class: JSQPhotoMediaItem'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105cb5c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010594ebb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105cb5b9d +[NSException raise:format:] + 205
3 ShitTalk 0x000000010393e7f1 -[PFObject _setObject:forKey:onlyIfDifferent:] + 750
4 ShitTalk 0x000000010393e4f0 -[PFObject setObject:forKey:] + 53
5 ShitTalk 0x000000010393e90f -[PFObject setObject:forKeyedSubscript:] + 50
6 ShitTalk 0x0000000103909e4a _TFC8ShitTalk22MessagesViewController23didPressAccessoryButtonfS0_FGSQCSo8UIButton_T_ + 1306
7 ShitTalk 0x000000010390a0f6 _TToFC8ShitTalk22MessagesViewController23didPressAccessoryButtonfS0_FGSQCSo8UIButton_T_ + 54
8 ShitTalk 0x000000010389866d -[JSQMessagesViewController messagesInputToolbar:didPressLeftBarButton:] + 125
9 ShitTalk 0x000000010387ebfd -[JSQMessagesInputToolbar jsq_leftBarButtonPressed:] + 93
10 UIKit 0x00000001062dfda2 -[UIApplication sendAction:to:from:forEvent:] + 75
11 UIKit 0x00000001063f154a -[UIControl _sendActionsForEvents:withEvent:] + 467
12 UIKit 0x00000001063f0919 -[UIControl touchesEnded:withEvent:] + 522
13 UIKit 0x000000010668aa10 _UIGestureRecognizerUpdate + 9487
14 UIKit 0x000000010632c686 -[UIWindow _sendGesturesForEvent:] + 1041
15 UIKit 0x000000010632d2b2 -[UIWindow sendEvent:] + 666
16 UIKit 0x00000001062f3581 -[UIApplication sendEvent:] + 246
17 UIKit 0x0000000106300d1c _UIApplicationHandleEventFromQueueEvent + 18265
18 UIKit 0x00000001062db5dc _UIApplicationHandleEventQueue + 2066
19 CoreFoundation 0x0000000105be9431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x0000000105bdf2fd __CFRunLoopDoSources0 + 269
21 CoreFoundation 0x0000000105bde934 __CFRunLoopRun + 868
22 CoreFoundation 0x0000000105bde366 CFRunLoopRunSpecific + 470
23 GraphicsServices 0x000000010a368a3e GSEventRunModal + 161
24 UIKit 0x00000001062de900 UIApplicationMain + 1282
25 ShitTalk 0x00000001038afe57 main + 135
26 libdyld.dylib 0x0000000107fda145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I did it successfully with Parse and JSQMessages but in ObjectiveC. Please look at my version of code and see if this is of any help?
}
And here is how I am loading it back