{"id":27226226,"url":"https://github.com/mumble-srl/mpush-swift","last_synced_at":"2026-01-30T01:42:46.980Z","repository":{"id":34303954,"uuid":"165016727","full_name":"Mumble-SRL/MPush-Swift","owner":"Mumble-SRL","description":"MPush iOS SDK","archived":false,"fork":false,"pushed_at":"2024-10-29T15:46:24.000Z","size":2811,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T13:36:37.324Z","etag":null,"topics":["cocoapods","mpush","notifications","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mumble-SRL.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}},"created_at":"2019-01-10T08:00:38.000Z","updated_at":"2024-10-29T15:46:21.000Z","dependencies_parsed_at":"2022-08-08T00:15:52.527Z","dependency_job_id":null,"html_url":"https://github.com/Mumble-SRL/MPush-Swift","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mumble-SRL%2FMPush-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mumble-SRL%2FMPush-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mumble-SRL%2FMPush-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mumble-SRL%2FMPush-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mumble-SRL","download_url":"https://codeload.github.com/Mumble-SRL/MPush-Swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248215196,"owners_count":21066622,"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":["cocoapods","mpush","notifications","xcode"],"created_at":"2025-04-10T11:55:05.521Z","updated_at":"2026-01-30T01:42:46.910Z","avatar_url":"https://github.com/Mumble-SRL.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\" \u003e\n\u003cimg src=\"https://raw.githubusercontent.com/Mumble-SRL/MPush-Swift/master/Images/mpush-icon.png\" alt=\"MBurger Logo\" title=\"MBurger Logo\"\u003e\n\u003c/p\u003e\n\n# MPush iOS SDK\n[![Documentation](https://img.shields.io/badge/documentation-100%25-brightgreen.svg)](https://github.com/Mumble-SRL/MPush-Swift/tree/master/docs)\n[![](https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat)](https://swift.org/package-manager/)\n[![CocoaPods](https://img.shields.io/badge/pod-v0.4.2-blue.svg)](https://cocoapods.org)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](LICENSE)\n\nMPush is a client libary, written in Swift, that can be used to interact with the [MPush](https://mpush.app) API. The minimum deplaoyment target for the library is iOS 11.0. \n\nMPush uses a classic Pub/Sub pattern, you will register your devce to topics, then from the MPush apis you will be able to send notifications to those topics and all device registered will receive a notification.\n\nA topic can represent whatever you want in your system (e.g. the entire app, a user a subset of user with a common charachteristic) so you will be able to choose the granularity of the notifications.\n\n# Minimum Requirements\n\n- [Swift 4.0+](https://github.com/pusher/push-notifications-swift/commit/d6dfa2186195135d8d7d1e3d3efdd7f8661ea404)\n- [Xcode](https://itunes.apple.com/us/app/xcode/id497799835) - The easiest way to get Xcode is from the [App Store](https://itunes.apple.com/us/app/xcode/id497799835?mt=12), but you can also download it from [developer.apple.com](https://developer.apple.com/) if you have an AppleID registered with an Apple Developer account.\n\n# Installation\n\n## Swift Package Manager\n\nWith Xcode 11 you can start using [Swift Package Manager](https://swift.org/package-manager/) to add **MPushSwift** to your project. Follow those simple steps:\n\n* In Xcode go to File \u003e Swift Packages \u003e Add Package Dependency.\n* Enter `https://github.com/Mumble-SRL/MPushSwift.git` in the \"Choose Package Repository\" dialog and press Next.\n* Specify the version using rule \"Up to Next Major\" with \"0.2.13\" as its earliest version and press Next.\n* Xcode will try to resolving the version, after this, you can choose the `MPushSwift` library and add it to your app target.\n\n## CocoaPods\nCocoaPods is a dependency manager for iOS, which automates and simplifies the process of using 3rd-party libraries in your projects. You can install CocoaPods with the following command:\n\n```ruby\n$ gem install cocoapods\n```\nTo integrate the MPush into your Xcode project using CocoaPods, specify it in your Podfile:\n\n```ruby\nplatform :ios, '10.0'\n\ntarget 'TargetName' do\n\tuse_frameworks!\n\n    pod 'MPushSwift'\nend\n```\n\nThen, run the following command:\n\n```\n$ pod install\n```\n\nCocoaPods is the preferred methot to install the library.\n\n## Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate MPushSwift into your Xcode project using Carthage, specify it in your Cartfile:\n\n```\ngithub \"Mumble-SRL/MPushSwift\"\n```\n\n## Manual installation\n\nTo install the library manually drag and drop the folder `MPush` to your project structure in XCode. \n\nNote that `MPush` has `MBNetworking (1.0)` as dependency, so you have to install also this library.\n\n# Usage\n\nThe first thig you have to do is implement Push Notifications using the [UserNotifications](https://developer.apple.com/documentation/usernotifications) framework.\n\n\u003e You will be guided through all the steps needed to have a functional project wth the push notifications, if you have already done it you can skip to the [Integrate MPush](#integrate-mpush) section of this README.\n\n\n# Create a key\n\nGo to [developer.apple.com](https://www.developer.apple.com) with an admin account and under Keys -\u003e All click the plus button in the top right corner.\n Specify a name for your key and enable Apple Push Notifications service (APNs).\n\n![Key creation 1](https://raw.githubusercontent.com/Mumble-SRL/MPush-Swift/master/Images/Key-creation-1.png)\n![Key creation 2](https://raw.githubusercontent.com/Mumble-SRL/MPush-Swift/master/Images/Key-creation-2.png)\n\nThen download the .p8 key file created and upload it in our [dashboard](https://mpush.app).\n\n\u003e Note that the key created is valid for all the apps of your profile and can't be re-downloaded, keep it in a safe place because you will likely have to resue it.\n\n# Add notifications to your app\n\nNow go to your app settings under Identifier -\u003e AppId and enable the notifications services following the steps. After that you need to update the Provisioning Profile for your app or create a new one because push notifications donesn't work for applications signed with a wildcard Provisioning Profile.\n\nNow it's finally time to move to XCode. Open your project and enable push notifications in the capabilities tab.\n\n![XCode-capabilities](https://raw.githubusercontent.com/Mumble-SRL/MPush-Swift/master/Images/XCode-capabilities.png)\n\nIn `AppDelegate.swift` add\n\n```swift\nimport UserNotifications\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n    ...\n    \n    let userNotificationCenter = UNUserNotificationCenter.current()\n    userNotificationCenter.delegate = self\n\n    self.registerForPushNotifications()\n\t...\n}\n\n// MARK: - Notifications\n    \nfunc registerForPushNotifications() {\n    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, _) in\n        guard granted else { return }\n        self.getNotificationSettings()\n    }\n}\n    \nfunc getNotificationSettings() {\n    UNUserNotificationCenter.current().getNotificationSettings { (settings) in\n        guard settings.authorizationStatus == .authorized else { return }\n        DispatchQueue.main.async {\n            UIApplication.shared.registerForRemoteNotifications()\n        }\n    }\n}\n\nextension AppDelegate: UNUserNotificationCenterDelegate {\n    func userNotificationCenter(_ center: UNUserNotificationCenter,\n                                willPresent notification: UNNotification,\n                                withCompletionHandler\n                                completionHandler: @escaping (UNNotificationPresentationOptions) -\u003e Void) {\n        completionHandler(UNNotificationPresentationOptions.alert)\n    }\n    \n    func userNotificationCenter(_ center: UNUserNotificationCenter,\n                                didReceive response: UNNotificationResponse,\n                                withCompletionHandler\n                                completionHandler: @escaping () -\u003e Void) {\n        completionHandler()\n    }\n}\n\n```\n\n# Integrate MPush\n\nTo integrate MPush to your implementation you need to add this in your AppDelegate\n\n```swift\nimport MPushSwift\n\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -\u003e Bool {\n    ...\n    MPush.token = \"YOUR_PUSH_TOKEN\"\n    ...\n}\n\n...\n\nfunc application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n    MPush.registerDevice(deviceToken: deviceToken, success: {\n        MPush.register(toTopic: MPTopic(\"YOUR_TOPIC\"))\n        // OR if you have more than one topic\n        // MPush.register(toTopics: [MPTopic(\"TOPIC1\"), MPTopic(\"TOPIC2\")])\n    })\n}\n\n```\nYou're set 🎉, the device will receive notifications for the topic is registered to. \n\n### MPTopic additional parameters\n\nWhen creating topic you can specify additional parameters:\n\n* `title`: a title fot that topic that will be displayed in the dashboard, if not specified it has the same value as the topic id\n* `single`: If the topic identifies a single user or a group of users, defaults to `false`\n\n# Rich Notifications\n\nTo implement rich notifications you will have to create a new Notificaiton Service Target that will be responsible for downloading the media of the notification and attach it to the notification object.\n\nIn Xcode go to File -\u003e New -\u003e Target and choose Notification Service Extension\n\n\u003e Keep in mind that notifications don't have much time to download the media attached, if the dowload doen't finish in a short period of time the notification will be delivered without the media.\n\nTo handle MPush attachments add this your `NotificationService` should look like this:\n\n```swift\noverride func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -\u003e Void) {\n    self.contentHandler = contentHandler\n    bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)\n    \n    if let bestAttemptContent = bestAttemptContent {\n        if let mediaUrl = request.content.userInfo[\"media_url\"] as? String, let fileUrl = URL(string: mediaUrl) {\n            downloadMedia(fileUrl: fileUrl, request: request, bestAttemptContent: bestAttemptContent) {\n                contentHandler(bestAttemptContent)\n            }\n        } else {\n            contentHandler(bestAttemptContent)\n        }\n    }\n}\n    \nfunc downloadMedia(fileUrl: URL, request: UNNotificationRequest, bestAttemptContent: UNMutableNotificationContent, completion: @escaping () -\u003e Void) {\n    let task = URLSession.shared.downloadTask(with: fileUrl) { (location, _, _) in\n        if let location = location {\n            let tmpDirectory = NSTemporaryDirectory()\n            let tmpFile = \"file://\".appending(tmpDirectory).appending(fileUrl.lastPathComponent)\n            let tmpUrl = URL(string: tmpFile)!\n            do {\n                try FileManager.default.moveItem(at: location, to: tmpUrl)\n                \n                var options: [String: String]? = nil\n                if let type = request.content.userInfo[\"media_type\"] as? String {\n                    options = [String: String]()\n                    options?[UNNotificationAttachmentOptionsTypeHintKey] = type\n                }\n                if let attachment = try? UNNotificationAttachment(identifier: \"media.\" + fileUrl.pathExtension, url: tmpUrl, options: options) {\n                    bestAttemptContent.attachments = [attachment]\n                }\n                completion()\n            } catch {\n                completion()\n            }\n        }\n    }\n    task.resume()\n}\n\noverride func serviceExtensionTimeWillExpire() {\n    // Called just before the extension will be terminated by the system.\n    // Use this as an opportunity to deliver your \"best attempt\" at modified content, otherwise the original push payload will be used.\n    if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {\n        contentHandler(bestAttemptContent)\n    }\n}\n```\n\nWith this code we download the attachemnt, if exists, and move it to a temporary directory. Then we add it to our notification with \n\n```swift\nif let attachment = try? UNNotificationAttachment(identifier: \"media.\" + fileUrl.pathExtension, url: tmpUrl, options: options) {\n    bestAttemptContent.attachments = [attachment]\n}\n```\n\n# License\n\nMPush is released under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumble-srl%2Fmpush-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmumble-srl%2Fmpush-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmumble-srl%2Fmpush-swift/lists"}