Referd Developers Guide
  • Referd Developers Docs
  • Introduction
  • Installing Referd
    • iOS
      • Getting Started
      • Initialize Referd User Profile
      • Track User Events
      • Push Notifications
      • Go-Live Checklist
    • Android
      • Getting Started
      • Initialize Referd User Profile
      • Track Referd Events
      • Push Notifications
      • Go-Live Checklist
    • React Native
      • Getting Started
      • Initialize Referd User Profile
      • Track User Events
      • Push Notifications
      • Go-Live Checklist
    • Flutter
      • Getting Started
      • Initialize Referd User Profile
      • Track User Events
      • Go-Live Checklist
    • Generic Mobile App
      • Initialize Referd User Profile
      • Track User Events
      • Push Notifications
      • Go-Live Checklist
  • REST API
    • Overview
    • Authentication
    • API Reference
      • User
      • Event
      • Notifications
    • API Endpoint Testing
    • Errors
Powered by GitBook
On this page
  • Configure Referd With Your Firebase
  • Handling Push Notifications Integration
  1. Installing Referd
  2. iOS

Push Notifications

Integrate your app with Referd push notifications and interactive in-app messaging.

Last updated 1 year ago

Referd uses Firebase to deliver maximum experience in your app. This includes push notifications, interactive in-app messaging and referrals support.

Configure Referd With Your Firebase

Handling Push Notifications Integration

Configure notifications as usual and add two more methods using our SDK. This is normal integration for general firebase notifications configuration, so here is a how-to guide.

1. Add the below to the AppDelegate class

Inherit :UNUserNotificationCenterDelegate, MessagingDelegate
Add var gameballApp: Gameball?

2. Then put these lines didFinishLaunchingWithOptions() in AppDelegate

FirebaseApp.configure()
registerForPushNotifications()

3. Add these stack of lines to the AppDelegate class

    func registerForPushNotifications() {
        UNUserNotificationCenter.current()
            .requestAuthorization(options: [.alert, .sound, .badge]) {
                [weak self] granted, error in
                UNUserNotificationCenter.current().delegate = self
                Messaging.messaging().delegate = self
                guard granted else { return }
                self?.getNotificationSettings()
        }
    }

    func getNotificationSettings() {
        UNUserNotificationCenter.current().getNotificationSettings { settings in
            guard settings.authorizationStatus == .authorized else { return }
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }

4. Here we need to add this method to register token to Referd in this method

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
                let token = tokenParts.joined()
        if let refreshedToken = InstanceID.instanceID().token() {
            print("InstanceID token: (refreshedToken)")
            self.gameballApp?.registerDevice(withToken: refreshedToken)
        }
    }

5. Here we need to add this method to let Referd handle everything related to Referd Widget

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        gameballApp?.notificationPopUP(notification: notification)
    }

Your users can now receive push notifications from Referd.

Before you start, you must configure your Firebase on your Referd account. Follow the steps in article from our Help Center related to push notifications.

Configure your Firebase account on Referd for mobile push notifications