MonkeyKit 1.2.0

MonkeyKit 1.2.0

测试经过测试
语言语言 Obj-CObjective C
许可协议 Apache 2
发布日期最后发布2017年4月

Erika PerugachiGianni Carlo维护。



 
依赖
AFNetworking>= 0
UICKeyChainStore>= 0
 

MonkeyKit 1.2.0

  • Criptext, Inc.

开始使用

Playground

如果您将 SDK 作为 zip 文件下载,则会随 Monkey 一起提供 playground。它可以让你测试基本的发送消息和图像等功能。

初始化 Monkey

#####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)
        })
    }
}
  • 您可以在我们的 管理员面板 上注册以获取应用密钥和密钥。
  • 您可以使用您想要的任何参数定义自己的用户元数据。如果您已经有一个想要重复使用的 Monkey ID,只需在元数据中定义一个值为该 ID 的 monkeyId 键。
  • 您可以通过发送一个要忽略的用户元数据键数组来防止 Monkey 存储敏感用户信息。
  • 如果您不重复使用 Monkey ID,您可以定义生成的 Monkey ID 是临时的还是永久性的。
  • 如果您想看到 Monkey 打印的所有日志,将调试设置为 true。
  • 要请求在每次连接到我们的服务器时自动请求挂起的消息,将 autoSync 设置为 true。

连接时发送消息

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 文件。