- iOS 10.0+
- Xcode 10.2+
- Swift 5+
- Set up a Firebase Cloud Messaging
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Our SDK into your Xcode project using CocoaPods, specify it in your Podfile
:
target 'your_project_name' do
pod 'CollectaPushSDK'
end
Then install the pods using pod install --repo-update
You can add CollectaPushSDK initialization code to your application either at startup ,or at the desired point in your application flow. Import the CollectaPushSDK module and configure a shared instance as shown:
-
Import the CollectaPushSDK module in your
UIApplicationDelegate
:import CollectaPushSDK
-
Configure a CollectaPushSDK shared instance, typically in your app's
messaging(_:didReceiveRegistrationToken:)
method to be notified whenever the firebase token is updated:CollectaPushSDK.shared.initialize(username:"your-user-name", password: "your-password", source:"source-1", uuid:"user-id", fcmToken:fcmToken)
Parameters:
username
-> username we providepassword
-> password we providesource
-> source we provideuuid
-> unique id for the userfcmToken
-> Firebase registration token
-
To respond to the delivery of notifications, you must implement a delegate for the shared
UNUserNotificationCenter
object inapplication(_:didFinishLaunchingWithOptions:)
:UNUserNotificationCenter.current().delegate = self
-
Your delegate object must conform to the
UNUserNotificationCenterDelegate
protocol ,and implement theuserNotificationCenter(_:didReceive:withCompletionHandler:)
anduserNotificationCenter(_:willPresent:withCompletionHandler:)
methods.func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo CollectaPushSDK.shared.didReceiveMessage(userInfo:userInfo) completionHandler() } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler:@escaping(UNNotificationPresentationOptions)->Void) { completionHandler([.alert,.sound,.badge]) }
We want to modify the payload of a remote notification before it's displayed on the user’s iOS device so we use UNNotificationServiceExtension.
- In Xcode Select
File
>New
>Target
... - Select
Notification Service Extension
then press Next. - Enter the product name as
MyNotificationServiceExtension
and press Finish. - Press Cancel on the Activate scheme prompt. By cancelling, you are keeping Xcode debugging your app, instead of just the extension. If you activate by accident, you can always switch back to debug your app within Xcode (next to the play button).
- In the project navigator, select the top level project directory and select the
MyNotificationServiceExtension
target in the project and targets list. Unless you have a specific reason not to, you should set theDeployment Target
to be iOS 10. - Open
NotificationService.swift
and add ourdidReceiveNotificationExtensionRequest
method todidReceive(_ request:withContentHandler:)
method as shown belowoverride func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) CollectaPushSDK.shared.didReceiveNotificationExtensionRequest(request, withContentHandler:contentHandler) }
- Add the CollectaPushSDK dependency under your project name target as well as
MyNotificationServiceExtension
target like belowtarget 'your_project_name' do pod 'CollectaPushSDK' end target 'MyNotificationServiceExtension' do pod 'CollectaPushSDK' end
Then install the pods using pod install --repo-update
Collecta SDK is owned and maintained by the MEDRICS Healthcare Solutions Corp. You can follow us on Linkedin at MEDRICS for project updates and releases.
Copyright © 2020 MEDRICS Healthcare Solutions Corp. All rights reserved.