'Banner of local notification from broadcast upload extension may not work

I implemented a broadcast upload extension and it requests local notifications. The local notification works normally, I mean that it works for both Banner and Notification Center, on broadcastStarted(withSetupInfo:), but the Banner of the local notification does not work on processSampleBuffer(_: with:) though its Notification Center works normally.

What am I missing?

Here is my code snippets.

  • container app
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
 
        requestAuthorization()
        ...
}

    private func requestAuthorization() {
        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options: [.alert]) { granted, error in
             
            if let error = error {
                // Handle the error here.
                print(error)
            }
            if granted == true {
                center.delegate = self
                center.getNotificationSettings(completionHandler: { setting in
                    print(setting)
                })
            }
            else {
                print("not permitted")
            }
        }
    }
}
  • upload extension
class SampleHandler: RPBroadcastSampleHandler {
    override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
        super.broadcastStarted(withSetupInfo: setupInfo)

        notification(title: "Upload Extension", body: "broadcastStarted")
        ...
    }

    override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
        super.processSampleBuffer(sampleBuffer, with: sampleBufferType)
        ...
        if some condition {
            notification(title: "Upload Extension", body: "processSampleBuffer")
        }
    }

    private func notification(title: String, body: String) {
        let content = UNMutableNotificationContent()
        content.title = title
        content.body = body
        let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
        let notificationCenter = UNUserNotificationCenter.current()
        notificationCenter.add(request) { error in
           if error != nil {
              print(error)
           }
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source