SDKs

iOS - Push Notifications

Overview

DataSenses allows you to send push notifications to your applications from our dashboard. Please follow the steps to send your first push notification to your application. Please note to test remote push notifications you need to connect your actual iOS device. The remote push notifications don't work on simulator.

Configure Push Notifications with DataSenses

Installation

  1. Go to Apple developer account and go to Certificates, Identifiers & Profiles
  2. Go to Keys section and click on a new key using Add button(+).
  3. Download keys and upload to DataSenses (.p8 is recommended) with Key ID and Team ID (You will get your Team ID from Apple Developer Account. Go to Membership tab and get your Team ID)

img.png

img_1.png

img_2.png

Upload to DataSenses' Dashboard img.png

Share firebase notification token to DataSenses

The following code is an example of how to send the notification token to DataSenses

  1. Add Push Notification in Signing & Capabilities in Xcode. Below is an example how to implement your owned notification system and share the token to DataSenses.
import FirebaseMessaging

func initializeFirebase() {
     FirebaseApp.configure()
 }
 
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {                
        initializeFirebase() // Must have, if you already integrated with firebase, don't need this function
        Messaging.messaging().delegate = self
        UNUserNotificationCenter.current().delegate = self
        
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { success, _ in
            guard success else {
                return
            }
            print("Success in APNS")
            
        }
        application.registerForRemoteNotifications()
                                        
        return status
    }
        
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    }
    
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        var formattedAPNSToken = ""
        if let apnsTokenData = Messaging.messaging().apnsToken {
            formattedAPNSToken = apnsTokenData.map { String(format: "%02.2hhx", $0) }.joined()
            print("APNs token: \(formattedAPNSToken)")
        }
    
        print("FCM token: \(fcmToken ?? "")")
        
        Datasenses.shared().registerPushNotification(token: fcmToken, apnToken: formattedAPNSToken)
    }

If your team is using Firebase as your messaging system. Please read the following

Configuration

  1. Go to the FCM console. then go to Project Overview -> Project settings

  2. Copy the Project ID. You will need it at a later stage in the process. img.png

  3. Go to the Cloud Messaging tab. Make sure that Firebase Cloud Messaging API (V1) is set to Enabled

  4. To assign DataSenses the uninstall role:

    • Go to the Service accounts tab
    • Click Manage service account permissions. A new browser tab opens in Google Cloud Platform
    • In the side menu, select Roles.
  5. Complete as follows:

    • Title: Enter DataSenses uninstalls.
    • ID: Enter ds_uninstalls.
    • Role launch stage: Select General availability.
  6. Click Add Permissions

  7. In Filter, Select the cloudmessaging.messages.create permission img.png

  8. Click Add and then click Create

  9. To assign DataSenses the FCM uninstall role:

    • In the side menu, select IAM
    • Open the PERMISSIONS -> VIEW BY PRINCIPALS tab
    • Click Grant Access
    • In Add Principals -> New principals, enter ds-uninstall-tracking@ds-uninstall-tracking.iam.gserviceaccount.com
    • In Assign roles -> Role select the custom you created -> DataSenses uninstalls
    • Click Save.
Previous
iOS SDK