skip to Main Content

I’ve built an app for close family and friends to use. I can’t upload the app to the App Store as I’m using copyrighted material/assets so I’m using TestFlight to distribute the app to allow my family and friends to use it.
I’ve implemented local notifications in the app using UserNotifications, UNUserNotificationCenter, etc.. I schedule two notifications per week that should be delivered at the same time every week, each on separate days of the week. However, my personal device is the only one that is actually receiving these notifications, and everyone one of my ‘users’ who downloaded my app via TestFlight do not get these notifications. I’ve verified that my ‘users’ do have notifications turned on for my app.

Initially I followed a YouTube video on how to implement local notifications. The approach shown in the video uses the completion handler APIs of UserNotification. I’ve also tried experimenting with using the async APIs instead since my app follows async await architecture but this didn’t help.

Although maybe not best practice, my implementation is as follows:

  1. When user loads app, run loop to schedule all ~30 notifications.
  2. In each iteration, create the notification with a unique identifier per notification.
  3. Remove any pending notifications matching that identifier.
  4. Add the created notification to the queue.

I also ask for user permission to send notifications like this:

func checkForNotificationsPermission() {
        let notificationCenter = UNUserNotificationCenter.current()
        notificationCenter.getNotificationSettings { settings in
            switch settings.authorizationStatus {
            case .authorized:
                self.dispatchNotifications()
            case .notDetermined:
                notificationCenter.requestAuthorization(options: [.alert, .sound]) { didAllow, error in
                    if didAllow {
                        self.dispatchNotifications()
                    }
                }
            default:
                return
            }
        }
    }

where dispatchNotifications() follows steps 1-4 above.

My best assumption is that the notifications work for me because I’m the account that’s tied to the developer account and I have some certificate to allow notifications but I don’t know for sure. All the people using my app via TestFlight are added to my App Store Connect with the role of "Marketing".

2

Answers


  1. Make sure you request notification permissions at app startup.

    Login or Signup to reply.
  2. Make sure to :

    • Register to notification in AppDelegate:

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.alert, .sound, .badge])}

    • in didFinishLaunchingWithOptions :

         func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
       UNUserNotificationCenter.current().delegate = self
       return true}
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search