没有这样的模块错误

时间:2016-04-06 02:16:28

标签: swift

我正在使用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
    }
}
}

2 个答案:

答案 0 :(得分:10)

执行以下操作,您可以从" Pods"

导入任何swift文件
  

1)清理你的项目

     

2)确保你所有的" Pods" > "构建设置" > "建立活跃   仅限架构"设置为" NO"。

     

3)不要跑步,只需建立你的项目。

     

4)现在,从" Pods"中导入任何文件。任何快速文件

     

例如:导入JSQMessagesViewController

     

5)再次,构建项目,它将按预期工作。最后,你可以   访问它的属性

希望这有帮助!

答案 1 :(得分:2)

安装Pod后,关闭xCode。然后使用以下命令行将其打开:

  

$ open App.xcworkspace

我遇到了与你相同的问题,它对我有用。从https://cocoapods.org/获取此信息。