{"id":14963490,"url":"https://github.com/emqx/cocoamqtt","last_synced_at":"2026-03-05T08:05:57.674Z","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":"2025-04-04T01:54:53.000Z","size":1726,"stargazers_count":1649,"open_issues_count":153,"forks_count":444,"subscribers_count":78,"default_branch":"master","last_synced_at":"2025-04-26T12:01:47.323Z","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}},"created_at":"2014-07-28T00:45:09.000Z","updated_at":"2025-04-24T19:40:38.000Z","dependencies_parsed_at":"2024-05-21T11:01:24.152Z","dependency_job_id":"09bee97d-139f-46da-b18c-0215e953b96d","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":69,"template":false,"template_full_name":null,"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","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251558541,"owners_count":21608841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-03-05T08:05:57.618Z","avatar_url":"https://github.com/emqx.png","language":"Swift","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### 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\n### Carthage\nInstall using [Carthage](https://github.com/Carthage/Carthage) by adding the following lines to your Cartfile:\n\n```\ngithub \"emqx/CocoaMQTT\" \"master\"\n```\n\nThen, run the following command:\n\n```bash\n$ carthage update --platform iOS,macOS,tvOS --use-xcframeworks\n```\n\nAt last:\n\nOn your application targets “General” settings tab, in the \"Frameworks, Libraries, and Embedded content\" section, drag and drop CocoaMQTT.xcframework, CocoaAsyncSocket.xcframework and Starscream.xcframework from the Carthage/Build folder on disk. Then select \"Embed \u0026 Sign\". \n\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 **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```\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\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 fisrt:\n\n```bash\n$ cd Examples\n\n$ pod install\n```\n\nThen, open the `Example.xcworkspace/` by Xcode and start it!\n\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","funding_links":[],"categories":[],"sub_categories":[],"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"}