{"id":14963490,"url":"https://github.com/emqx/cocoamqtt","last_synced_at":"2026-06-30T04:00:45.355Z","repository":{"id":19098212,"uuid":"22326416","full_name":"emqx/CocoaMQTT","owner":"emqx","description":"MQTT 5.0 client library for iOS and macOS written in Swift","archived":false,"fork":false,"pushed_at":"2026-06-26T07:47:10.000Z","size":1939,"stargazers_count":1747,"open_issues_count":142,"forks_count":473,"subscribers_count":75,"default_branch":"master","last_synced_at":"2026-06-26T09:04:38.611Z","etag":null,"topics":["cocoamqtt","cocoapods","ios","macos","macosx","mqtt","mqtt-client","swift","tvos"],"latest_commit_sha":null,"homepage":"https://www.emqx.com/en","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emqx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2014-07-28T00:45:09.000Z","updated_at":"2026-06-18T09:58:59.000Z","dependencies_parsed_at":"2026-06-26T09:00:47.551Z","dependency_job_id":null,"html_url":"https://github.com/emqx/CocoaMQTT","commit_stats":{"total_commits":384,"total_committers":80,"mean_commits":4.8,"dds":0.7942708333333334,"last_synced_commit":"4abf2d10315dff60661a32f1db5dcc45a9df9f09"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"purl":"pkg:github/emqx/CocoaMQTT","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2FCocoaMQTT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2FCocoaMQTT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2FCocoaMQTT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2FCocoaMQTT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emqx","download_url":"https://codeload.github.com/emqx/CocoaMQTT/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emqx%2FCocoaMQTT/sbom","scorecard":{"id":376339,"data":{"date":"2025-08-11","repo":{"name":"github.com/emqx/CocoaMQTT","commit":"f183e8d03eb4f8c050d6b698417fa815012b8746"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.6,"checks":[{"name":"Code-Review","score":5,"reason":"Found 12/22 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact 2.1.3 not signed: https://api.github.com/repos/emqx/CocoaMQTT/releases/94515853","Warn: release artifact 2.1.3 does not have provenance: https://api.github.com/repos/emqx/CocoaMQTT/releases/94515853"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":3,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'master'","Warn: could not determine whether codeowners review is allowed","Warn: no status checks found to merge onto branch 'master'","Warn: PRs are not required to make changes on branch 'master'; or we don't have data to detect it.If you think it might be the latter, make sure to run Scorecard with a PAT or use Repo Rules (that are always public) instead of Branch Protection settings"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 20 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T14:20:11.796Z","repository_id":19098212,"created_at":"2025-08-18T14:20:11.796Z","updated_at":"2025-08-18T14:20:11.796Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34951598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoamqtt","cocoapods","ios","macos","macosx","mqtt","mqtt-client","swift","tvos"],"created_at":"2024-09-24T13:31:36.731Z","updated_at":"2026-06-30T04:00:45.349Z","avatar_url":"https://github.com/emqx.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CocoaMQTT\n\n![PodVersion](https://img.shields.io/cocoapods/v/CocoaMQTT5.svg)\n![Platforms](https://img.shields.io/cocoapods/p/CocoaMQTT5.svg)\n![License](https://img.shields.io/cocoapods/l/BadgeSwift.svg?style=flat)\n![Swift version](https://img.shields.io/badge/swift-5-orange.svg)\n\nMQTT v3.1.1 and v5.0 client library for iOS/macOS/tvOS written with Swift 5\n\n\n## Build\n\nBuild with Xcode 11.1 / Swift 5.1\n\nIOS Target: 12.0 or above\nOSX Target: 10.13 or above\nTVOS Target: 10.0 or above\n\n##  xcode 14.3 issue:\n```ruby\nFile not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a\n```\nIf you encounter the issue, Please update your project minimum depolyments to 11.0\n\n\n## Installation\n\n### Swift Package Manager\n\nTo integrate CocoaMQTT into your Xcode project using [Swift Package Manager](https://swift.org/package-manager/), follow these steps:\n\n1. Open your project in Xcode.\n2. Go to `File` \u003e `Swift Packages` \u003e `Add Package Dependency`.\n3. Enter the repository URL: `https://github.com/emqx/CocoaMQTT.git`.\n4. Choose the latest version or specify a version range.\n5. Add the package to your target.\n\nAt last, import \"CocoaMQTT\" to your project:\n\n```swift\nimport CocoaMQTT\n```\n\n### CocoaPods\n\nTo integrate CocoaMQTT into your Xcode project using [CocoaPods](http://cocoapods.org), you need to modify you `Podfile` like the followings:\n\n```ruby\nuse_frameworks!\n\ntarget 'Example' do\n    pod 'CocoaMQTT'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\nAt last, import \"CocoaMQTT\" to your project:\n\n```swift\nimport CocoaMQTT\n```\n\n## Usage\n\nCreate a client to connect [MQTT broker](https://www.emqx.com/en/mqtt/public-mqtt5-broker):\n\n```swift\n///MQTT 5.0\nlet clientID = \"CocoaMQTT-\" + String(ProcessInfo().processIdentifier)\nlet mqtt5 = CocoaMQTT5(clientID: clientID, host: \"broker.emqx.io\", port: 1883)\n\nlet connectProperties = MqttConnectProperties()\nconnectProperties.topicAliasMaximum = 0\nconnectProperties.sessionExpiryInterval = 0\nconnectProperties.receiveMaximum = 100\nconnectProperties.maximumPacketSize = 500\nmqtt5.connectProperties = connectProperties\n\nmqtt5.username = \"test\"\nmqtt5.password = \"public\"\nmqtt5.willMessage = CocoaMQTTMessage(topic: \"/will\", string: \"dieout\")\nmqtt5.keepAlive = 60\nmqtt5.delegate = self\nmqtt5.connect()\n\n///MQTT 3.1.1\nlet clientID = \"CocoaMQTT-\" + String(ProcessInfo().processIdentifier)\nlet mqtt = CocoaMQTT(clientID: clientID, host: \"broker.emqx.io\", port: 1883)\nmqtt.username = \"test\"\nmqtt.password = \"public\"\nmqtt.willMessage = CocoaMQTTMessage(topic: \"/will\", string: \"dieout\")\nmqtt.keepAlive = 60\nmqtt.delegate = self\nmqtt.connect()\n```\n\nNow you can use closures instead of `CocoaMQTTDelegate`:\n\n```swift \nmqtt.didReceiveMessage = { mqtt, message, id in\n    print(\"Message received in topic \\(message.topic) with payload \\(message.string!)\")           \n}\n```\n\n## SSL Secure\n\n#### One-way certification\n\nNo certificate is required locally.\nIf you want to trust all untrust CA certificates, you can do this:\n\n```swift\nmqtt.allowUntrustCACertificate = true\n```\n\n#### Two-way certification\n\nNeed a .p12 file which is generated by a public key file and a private key file. You can generate the p12 file in the terminal:\n\n```\nopenssl pkcs12 -export -clcerts -in client-cert.pem -inkey client-key.pem -out client.p12\n```\n\nNote: Please use openssl version 1.1 (e.g. `brew install openssl@1.1`), otherwise you may not be able to import the generated .p12 file to the system correctly.\n\n## MQTT over Websocket\n\nIn the 1.3.0, The CocoaMQTT has supported to connect to MQTT Broker by Websocket.\n\nIf you integrated by **Swift Package Manager**, follow these steps:\n\n1. Open your project in Xcode.\n2. Go to `File` \u003e `Swift Packages` \u003e `Add Package Dependency`.\n3. Enter the repository URL: `https://github.com/emqx/CocoaMQTT.git`.\n4. Choose the latest version or specify a version range.\n5. Add the package to your target.\n\nAt last, import \"CocoaMQTT\" and \"Starscream\" to your project:\n\n```swift\nimport CocoaMQTT\nimport CocoaMQTTWebSocket\nimport Starscream\n```\n\nIf you integrated by **CocoaPods**, you need to modify you `Podfile` like the followings and execute `pod install` again:\n\n```ruby\nuse_frameworks!\n\ntarget 'Example' do\n    pod 'CocoaMQTT/WebSockets'\nend\n```\n\nIf you're using CocoaMQTT in a project with only a `.podspec` and no `Podfile`, e.g. in a module for React Native, add this line to your `.podspec`:\n\n```ruby\nPod::Spec.new do |s|\n  ...\n  s.dependency \"Starscream\"\nend\n```\n\nThen, Create a MQTT instance over Websocket:\n\n```swift\n///MQTT 5.0\nlet websocket = CocoaMQTTWebSocket(uri: \"/mqtt\")\nlet mqtt5 = CocoaMQTT5(clientID: clientID, host: host, port: 8083, socket: websocket)\nlet connectProperties = MqttConnectProperties()\nconnectProperties.topicAliasMaximum = 0\n// ...\nmqtt5.connectProperties = connectProperties\n// ...\n\n_ = mqtt5.connect()\n\n///MQTT 3.1.1\nlet websocket = CocoaMQTTWebSocket(uri: \"/mqtt\")\nlet mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket)\n\n// ...\n\n_ = mqtt.connect()\n```\n\nIf you want to add additional custom header to the connection, you can use the following:\n\n```swift\nlet websocket = CocoaMQTTWebSocket(uri: \"/mqtt\")\nwebsocket.headers = [\n            \"x-api-key\": \"value\"\n        ]\n        websocket.enableSSL = true\n\nlet mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket)\n\n// ...\n\n_ = mqtt.connect()\n```\n\nIf you want to connect using WebSocket Secure (wss), you can use the following example:\n\n```swift\nimport CocoaMQTT\nimport CocoaMQTTWebSocket\nimport Starscream\n\nclass WebSocketManager {\n    \n    private var mqttClient: CocoaMQTT?\n    var message: String = \"\"\n    var token: String = \"\"\n\n    func setupMQTTClient(with token: String) {\n        let socket = CocoaMQTTWebSocket(uri: \"/mqtt\")\n        socket.enableSSL = true\n        mqttClient = CocoaMQTT(clientID: token, host: \"host\", port: 443, socket: socket)\n        mqttClient?.delegate = self\n    }\n\n    func connect() {\n        guard let mqttClient = mqttClient else { return }\n        mqttClient.connect()\n    }\n    \n}\n\nextension WebSocketManager: CocoaMQTTDelegate {\n    \n    func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -\u003e Void) {\n        // Implement your custom SSL validation logic here.\n        // For example, you might want to always trust the certificate for testing purposes:\n        completionHandler(true)\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -\u003e Void) {\n        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {\n            if let serverTrust = challenge.protectionSpace.serverTrust {\n                completionHandler(.useCredential, URLCredential(trust: serverTrust))\n                return\n            }\n        }\n        completionHandler(.performDefaultHandling, nil)\n    }\n    \n    func mqttUrlSession(_ mqtt: CocoaMQTT, didReceiveTrust trust: SecTrust, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -\u003e Void) {\n        \n        print(\"\\(#function), \\n result:- \\(challenge.debugDescription)\")\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didPublishAck id: UInt16) {\n        print(\"Published message with ID: \\(id)\")\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didUnsubscribeTopics topics: [String]) {\n        print(\"Unsubscribed from topics: \\(topics)\")\n    }\n    \n    func mqttDidPing(_ mqtt: CocoaMQTT) {\n        print(\"MQTT did ping\")\n    }\n    \n    func mqttDidReceivePong(_ mqtt: CocoaMQTT) {\n        print(\"MQTT did receive pong\")\n    }\n    \n    func mqttDidDisconnect(_ mqtt: CocoaMQTT, withError err: (any Error)?) {\n        print(\"Disconnected from MQTT broker with error: \\(String(describing: err))\")\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck) {\n        print(\"Connected to MQTT broker with acknowledgment: \\(ack)\")\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didReceiveMessage message: CocoaMQTTMessage, id: UInt16) {\n        if let messageString = message.string {\n            DispatchQueue.main.async {\n                self.message = messageString\n            }\n            print(\"Received message: \\(messageString) on topic: \\(message.topic)\")\n        }\n    }\n    \n    func mqtt(_ mqtt: CocoaMQTT, didPublishMessage message: CocoaMQTTMessage, id: UInt16) {\n        print(\"Published message: \\(message.string ?? \"\") with ID: \\(id)\")\n    }\n\n    func mqtt(_ mqtt: CocoaMQTT, didSubscribeTopics success: NSDictionary, failed: [String]) {\n        print(\"Subscribed to topics: \\(success), failed to subscribe to: \\(failed)\")\n    }\n\n    func mqtt(_ mqtt: CocoaMQTT, didDisconnectWithError err: Error?) {\n        print(\"Disconnected from MQTT broker with error: \\(String(describing: err))\")\n    }\n    \n}\n```\n\n## Example App\n\nYou can follow the Example App to learn how to use it. But we need to make the Example App works first:\n\n```bash\n$ cd Examples\n```\n\nThen, open the `Example.xcodeproj` by Xcode and start it!\n\n## Dependencies\n\n\nThese third-party functions are used:\n\n~~[GCDAsyncSocket](https://github.com/robbiehanson/CocoaAsyncSocket)~~\n* [MqttCocoaAsyncSocket](https://github.com/leeway1208/MqttCocoaAsyncSocket)\n* [Starscream](https://github.com/daltoniam/Starscream)\n\n\n## LICENSE\n\nMIT License (see `LICENSE`)\n\n## Contributors\n\n* [@andypiper](https://github.com/andypiper)\n* [@turtleDeng](https://github.com/turtleDeng)\n* [@jan-bednar](https://github.com/jan-bednar)\n* [@jmiltner](https://github.com/jmiltner)\n* [@manucheri](https://github.com/manucheri)\n* [@Cyrus Ingraham](https://github.com/cyrusingraham)\n\n## Author\n\n- Feng Lee \u003cfeng@emqx.io\u003e\n- CrazyWisdom \u003czh.whong@gmail.com\u003e\n- Alex Yu \u003calexyu.dc@gmail.com\u003e\n- Leeway \u003cleeway1208@gmail.com\u003e\n\n\n## Twitter\n\nhttps://twitter.com/EMQTech\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femqx%2Fcocoamqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femqx%2Fcocoamqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femqx%2Fcocoamqtt/lists"}