Skip to main content

Receive Push Notifications

  1. Add your iOS app on Firebase Console: Project Overview > Add App > iOS

  2. Download GoogleService-Info.plist

  3. Add GoogleService-Info.plist to the Xcode project (Add Files…, enable Copy items if needed). Select the plist in the Project Navigator, open the File Inspector (right sidebar, first tab), and under Target Membership check only your main application target—the target that produces your runnable app (usually named like your app). That tells Xcode to copy the plist into that app’s bundle so Firebase can load it. Do not check unrelated targets (e.g. tests or extensions) unless you intentionally use Firebase there too.

  4. Add the DashX packages: in Xcode go to FileAdd Package Dependencies…, enter https://github.com/dashxhq/dashx-ios.git, then add both DashX and DashXFirebase to your app target.

    info

    The CocoaPods DashX pod ships the core library only. DashXFirebase (including DashXAppDelegate) is provided via Swift Package Manager from the same repository.

  5. Add Firebase for iOS (for example pod 'FirebaseMessaging' in your Podfile and run pod install, or add the Firebase iOS SDK via Swift Package Manager). Ensure FirebaseApp.configure() runs before you rely on FCM.

  6. Implement DashXAppDelegate

import DashXFirebase
import FirebaseCore
import FirebaseMessaging

@main
class AppDelegate: DashXAppDelegate {

// ...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DashX.configure(
withPublicKey: "YOUR_PUBLIC_KEY"
)

// Initialize Firebase and FCM
FirebaseApp.configure()
Messaging.messaging().delegate = self

// Request permission for push notifications and handle the resulting authorization status
DashX.requestNotificationPermission { authorizationStatus in
switch authorizationStatus {
case .authorized:
// User has granted permission for push notifications
case .denied:
// User has denied permission for push notifications
case .notDetermined:
// User has not yet made a choice about push notifications
case .provisional:
// User has granted provisional permission for push notifications (iOS 12+)
@unknown default:
// Handle any future authorization status not accounted for in the switch statement
}
}

// This method registers the device token with DashX
DashX.subscribe()

return true
}

override func notificationDeliveredInForeground(message: [AnyHashable: Any]) -> UNNotificationPresentationOptions {
print("\n=== Notification Delivered In Foreground ===\n")
print(message)
print("\n=================================================\n")

// This is how you want to show your notification in the foreground
// You can pass "[]" to not show the notification to the user or
// handle this with your own custom styles
return [.sound, .alert, .badge]
}

override func notificationClicked(message: [AnyHashable: Any], actionIdentifier: String) {
print("\n=== Notification Clicked ===\n")
print(message)

// Get the required data from the notification message
let userId = message["USER_ID"] as! String

// Perform the task associated with the action.
switch actionIdentifier {
case "ACCEPT_ACTION": APIManager.accept(userId: userId)
case "DECLINE_ACTION": APIManager.decline(userId: userId)
// handle other actions
default: break
}

print("\n=================================\n")
}
}
  1. Disable swizzling for Firebase

Add the FirebaseAppDelegateProxyEnabled key in the app’s Info.plist and set it to NO (boolean).