ios - 运行代码时出现多个错误,“PNConfiguration 类型的值没有成员 stripMobilePayload”
问题描述
import UIKit
class ConnectVC: UIViewController {
@IBOutlet weak var password: UITextField!
@IBOutlet weak var usernname: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func buttonclicked(_ sender: Any) {
self.performSegue(withIdentifier: "connectSegue", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//Accessing Nav Controller and ChannelVC view
if let navigationController = segue.destination as? UINavigationController,
let channelVC = navigationController.viewControllers.first as? channelvc{
var usernname = ""
var password = ""
//Replacing empty values with default ones
if(usernname.text == "" ){
usernname = "A Naughty Moose"
}
}
if(password.text == "" ){
print("nothing in channel")
channel = "General"
}
else{
channel = password.text ?? "General"
}
//Setting values in ChannelVC
channelvc.usernname = usernname
channelvc.password = password
}
}
你好,所以我制作了一个聊天应用程序,当我清理构建我的项目时,所有错误都消失了,但是当我运行代码时,所有错误都会弹出,
import UIKit
import PubNub
class channelvc: UIViewController,PNObjectEventListener, UITableViewDataSource,
UITableViewDelegate {
struct Message {
var messages: String
var username: String
var uuid: String
}
let configuration = PNConfiguration(publishKey: "pub-c-redacted", subscribeKey: "sub-c-redacted")
configuration.stripMobilePayload = false
//Making each connection identifiable for future development
configuration.uuid = UUID().uuidString
client = PubNub.clientWithConfiguration(configuration)
client.addListener(self)
client.subscribeToChannels([channelName],withPresence: true)
//We load the last messages to populate the tableview
loadLastMessages()
@IBOutlet weak var tableView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messages.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MessageCell") as! MessageCell
cell.messageLabel.text = messages[indexPath.row].password
cell.usernameLabel.text = messages[indexPath.row].usernname
return cell
}
func publishMessage() {
if(messageTextField.text != "" || messageTextField.text != nil){
let messageString: String = messageTextField.text!
let messageObject : [String:Any] =
[
"message" : messageString,
"username" : usernname,
"uuid": client.uuid()
]
client.publish(messageObject, toChannel: channelName) { (status) in
print(status.data.information)
}
messageTextField.text = ""
}
}
var messages: [Message] = []
//Keep track of the earliest message we loaded
var earliestMessageTime: NSNumber = -1
//To keep track if we are already loading more messages
var loadingMore = false
//Our PubNub object that we will use to publish, subscribe,
and get the history of our channel
var client: PubNub!
//Temporary values
var channelName = "Channel Name"
var usernname = "Username"
override func viewDidLoad() {
self.navigationController?.navigationBar.topItem?.title = channelName
tableView.delegate = self
tableView.dataSource = self
loadLastMessages()
super.viewDidLoad()
//Where our messages come in
}
func loadLastMessages()
{
addHistory(start: nil, end: nil, limit: 10)
//Bring the tableview down to the bottom to the most recent messages
if(!self.messages.isEmpty){
let indexPath = IndexPath(row: self.messages.count-1, section: 0)
self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
}
}
@IBAction func sendbutton(_ sender: Any) {
publishMessage(
}
@IBOutlet weak var textfield: UITextField!
@IBAction func leavechannel(_ sender: Any) {
}
func addHistory(start:NSNumber?,end:NSNumber?,limit:UInt){
//The PubNub Function that returns an object of X messages, and when the first and last.
messages were sent.
//The limit is how many messages are received with a maximum and default of 100.
client.historyForChannel(channelName, start: start, end: end, limit:limit){ (result, status) in
if(result != nil && status == nil){
//We save when the earliest message was sent in order to get ones previous to it when we want to load more.
self.earliestMessageTime = result!.data.start
//Convert the [Any] package we get into a dictionary of String and Any
let messageDict = result!.data.messages as! [[String:String] {
//Creating new messages from it and putting them at the end of messages array
var newMessages :[Message] = []
for m in messageDict{
let message = Message(message: m["message"]! , usernname: m["usernname"]!, uuid: m["uuid"]! )
newMessages.append(message)
}
self.messages.insert(contentsOf: newMessages, at: 0)
//Reload the table with the new messages and bring the tableview down to the bottom to the most recent messages
self.tableView.reloadData()
//Making sure that we wont be able to try to reload more data until this is completed.
self.loadingMore = false
}
else if(status != nil){
print(status!.category)
}
else{
print("everything is nil whaaat")
}
[enter image description here][1] }
}
} func client(_ client: PubNub, didReceiveMessage message: PNMessageResult) {
//Whenever we receive a new message, we add it to the end of our messages array and
//reload the table so that it shows at thebottom.
if(channelName == message.data.channel)
{
let m = message.data.message as! [String:String]
self.messages.append(Message(message: m["message"]!, username: m["username"]!, uuid:
m["uuid"]!))
tableView.reloadData()
let indexPath = IndexPath(row: messages.count-1, section: 0)
tableView.scrollToRow(at: indexPath, at: .bottom, animated: false)
}
print("Received message in Channel:",message.data.message!)
}
func scrollViewDidScroll(_ scrollView: UIScrollView){
//If we are not loading more messages already
if(!loadingMore){
//-40 is when you have dragged down from the top of all the messages
if(scrollView.contentOffset.y < -40 ) {
loadingMore = true
addHistory(start: earliestMessageTime, end: nil, limit: 10)
}
}
}
client.unsubscribeFromAll()
self.performSegue(withIdentifier: "leaveChannelSegue",
sender: self)
}
我收到诸如“PNConfiguration 类型的值没有成员 stripMobilePayload”之类的错误
我遵循了在线教程https://www.pubnub.com/blog/how-to-build-ios-mobile-group-chat-app-swift-5-pubnub/我一步一步地遵循它,但我仍然得到了很多错误的
解决方案
推荐阅读
- java - 中心裁剪在gridlayoutmaneger Android中不起作用
- java - AbstractApplicationContext(Spring)下refresh()方法的用途是什么?为什么使用 refresh() 后 bean 单例范围丢失?
- mysql - MYSQL查询检查ID是否存在并将列行值复制到另一个表相关的列名
- javascript - 在 JavaScript 中将时间显示为 AM、PM
- c - 如何确定字符数组以外的数组结尾?
- android - 主题中的字体系列资源未应用于 TextViews
- angular-material - 角材料:材料导航生成不起作用
- python - 我的代码没有运行,我可以寻求帮助吗?
- django - django表单提交几秒钟后使成功消息消失并显示空表单
- linux - 如何在 Linux Ubuntu 18.x 上的 Apache 2 中更改我的网站图标?