测试经过测试 | ✓ |
语言语言 | Obj-CObjective C |
许可协议 | Apache 2 |
发布日期最后发布 | 2017年4月 |
由Erika Perugachi、Gianni Carlo维护。
依赖 | |
AFNetworking | >= 0 |
UICKeyChainStore | >= 0 |
如果您将 SDK 作为 zip
文件下载,则会随 Monkey 一起提供 playground。它可以让你测试基本的发送消息和图像等功能。
#####Swift 导入 Monkey 并初始化它
import MonkeyKit
class MyController {
let AppId = "<Get your App Id from the Admin console>"
let AppSecret = "<Get your App secret from the Admin console>"
override func viewDidLoad() {
super.viewDidLoad()
//Define user metadata
let user = ["name":"Gianni",
"password": "53CR3TP455W0RD"]
//You can start Monkey with a Monkey Id
user["monkeyId"] = "<placeholder>"
//Define user metadata ignored params
let ignoredParams = ["password"]
/**
* Register listener to events regarding connection status changes
*/
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.handleConnectionChange(_:)), name: MonkeySocketStatusChangeNotification, object: nil)
/**
* Register listener to events regarding incoming messages
*/
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.messageReceived(_:)), name: MonkeyMessageNotification, object: nil)
/**
* Initialize Monkey
*/
Monkey.sharedInstance().initWithApp("idkgwf6ghcmyfvvrxqiwwmi",
secret: "9da5bbc32210ed6501de82927056b8d2",
user: user,
ignoredParams: ignoredParams,
expireSession: false,
debugging: true,
autoSync: true,
lastTimestamp: nil,
success: { (session) in
//print Monkey's current session
print(session)
},
failure: {(task, error) in
print(error.localizedDescription)
})
}
}
monkeyId
键。extenstion MyClass {
func handleConnectionChange(notification:NSNotification){
//handle connection changes
switch (notification.userInfo!["status"] as! NSNumber).unsignedIntValue{
case MOKConnectionStateDisconnected.rawValue:
print("disconnected")
break
case MOKConnectionStateConnecting.rawValue:
print("connecting")
break
case MOKConnectionStateConnected.rawValue:
print("connected")
//send test message
let recipientId = "Other Monkey Id"
Monkey.sharedInstance().sendText("Hello World!", toUser: recipientId)
break
case MOKConnectionStateNoNetwork.rawValue:
print("no network")
break
default:
break
}
}
}
其他用户将接收到该事件 MonkeyMessageNotification
监听的短信
extension MyClass {
func messageReceived(notification:NSNotification){
guard let userInfo = notification.userInfo, message = userInfo["message"] as? MOKMessage else {
return
}
print(message.sender)
print(message.recipient)
print(message.plainText)
}
}
Criptext Inc, [email protected]
MonkeyKit 可在 Apache v2.0 许可证下获得。有关更多信息,请参阅 LICENSE 文件。