CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | Apache 2 |
ReleasedLast Release | Apr 2017 |
Maintained by Erika Perugachi, Gianni Carlo.
Depends on: | |
AFNetworking | >= 0 |
UICKeyChainStore | >= 0 |
Monkey comes with a playground if you download the SDK as a zip
file. It will let you test basic functionality such as sending messages and images between two Monkey Ids.
#####Swift Import Monkey and initialize it
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
with the value.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
}
}
}
The other user will receive the message listening to this event 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 is available under the Apache v2.0 license. See the LICENSE file for more info.