我正在使用Swift聊天应用程序和可可豆荚,我一直在解决这个问题.它说没有这样的模块JSQMessagesViewController,并且pod文件的设置就像教程要我做的那样.如果你需要我给你看pod文件,请告诉我,我会把它放在那里.
谢谢吕克
这是代码.
import UIKit import JSQMessagesViewController import syncano_ios let syncanoChannelName = "messages" class ViewController: JSQMessagesViewController { let syncano = Syncano.sharedInstanceWithApiKey("7f5312e4808d69df6bd258b444b13d5d5956c15d",instanceName: "small-waterfall-9948") let channel = SCChannel(name: syncanoChannelName) let incomingBubble = JSQMessagesBubbleImageFactory().incomingMessagesBubbleImageWithColor(UIColor(red: 10/255,green: 180/255,blue: 230/255,alpha: 1.0)) let outgoingBubble = JSQMessagesBubbleImageFactory().outgoingMessagesBubbleImageWithColor(UIColor.lightGrayColor()) var messages = [JSQMessage]() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. self.setup() self.downloadNewestMessagesFromSyncano() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func reloadMessagesView() { self.collectionView?.reloadData() } } //MARK - Setup extension ViewController { func addDemoMessages() { for i in 1...10 { let sender = (i%2 == 0) ? "Server" : self.senderId let messageContent = "Message nr. \(i)" let message = JSQMessage(senderId: sender,displayName: sender,text: messageContent) self.messages += [message] } self.reloadMessagesView() } func setup() { self.senderId = UIDevice.currentDevice().identifierForVendor?.UUIDString self.senderDisplayName = UIDevice.currentDevice().identifierForVendor?.UUIDString self.channel.delegate = self self.channel.subscribetochannel() } } //MARK - Data Source extension ViewController { override func collectionView(collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int { return self.messages.count } override func collectionView(collectionView: JSQMessagesCollectionView!,messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! { let data = self.messages[indexPath.row] return data } override func collectionView(collectionView: JSQMessagesCollectionView!,didDeleteMessageAtIndexPath indexPath: NSIndexPath!) { self.messages.removeAtIndex(indexPath.row) } override func collectionView(collectionView: JSQMessagesCollectionView!,messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! { let data = messages[indexPath.row] switch(data.senderId) { case self.senderId: return self.outgoingBubble default: return self.incomingBubble } } override func collectionView(collectionView: JSQMessagesCollectionView!,avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! { return nil } } //MARK - Toolbar extension ViewController { override func didPressSendButton(button: UIButton!,withMessageText text: String!,senderId: String!,senderDisplayName: String!,date: NSDate!) { let message = JSQMessage(senderId: senderId,senderDisplayName: senderDisplayName,date: date,text: text) self.messages += [message] self.sendMessageToSyncano(message) self.finishSendingMessage() } override func didPressAccessoryButton(sender: UIButton!) { } } //MARK - Syncano extension ViewController { func sendMessageToSyncano(message: JSQMessage) { let messageToSend = Message() messageToSend.text = message.text messageToSend.senderId = self.senderId messageToSend.channel = syncanoChannelName messageToSend.other_permissions = .Full messageToSend.saveWithCompletionBlock { error in if (error != nil) { //Super cool error handling } } } func downloadNewestMessagesFromSyncano() { Message.please().giveMeDataObjectsWithCompletion { objects,error in if let messages = objects as? [Message]! { self.messages = self.jsqMessagesFromSyncanoMessages(messages) self.finishReceivingMessage() } } } func jsqMessageFromSyncanoMessage(message: Message) -> JSQMessage { let jsqMessage = JSQMessage(senderId: message.senderId,senderDisplayName: message.senderId,date: message.created_at,text: message.text) return jsqMessage } func jsqMessagesFromSyncanoMessages(messages: [Message]) -> [JSQMessage] { var jsqMessages : [JSQMessage] = [] for message in messages { jsqMessages.append(self.jsqMessageFromSyncanoMessage(message)) } return jsqMessages } } //MARK - Channels extension ViewController : SCChannelDelegate { func addMessageFromNotification(notification: SCChannelNotificationMessage) { let message = Message(fromDictionary: notification.payload) if message.senderId == self.senderId { //we don't need to add messages from ourselves return } self.messages.append(self.jsqMessageFromSyncanoMessage(message)) self.finishReceivingMessage() } func updateMessageFromNotification(notification: SCChannelNotificationMessage) { } func deleteMessageFromNotification(notification: SCChannelNotificationMessage) { } func chanellDidReceivedNotificationMessage(notificationMessage: SCChannelNotificationMessage!) { switch(notificationMessage.action) { case .Create: self.addMessageFromNotification(notificationMessage) case .Delete: self.deleteMessageFromNotification(notificationMessage) case .Update: self.updateMessageFromNotification(notificationMessage) default: break } } }
执行以下操作,您可以从“Pods”导入任何swift文件
1) Clean your project
2) Make sure that all your “Pods” > “Build Settings” > “Build Active
Architecture Only” is set to “NO”.3) Don’t run,just build your project.
4) Now,import any file from “Pods” to any swift file
E.g.: import JSQMessagesViewController
5) Again,build project and it will work as expected. Finally,you can
access it properties
希望这可以帮助!