1

A Notification Service Extension downloads a media file to display it as attachment of the UNNotification. However when the host app is in foreground, no notification is displayed, so it is unnecessary to for the notification extension to download the media file.

How can the download be prevented, depending on the app state?

Manuel
  • 14,274
  • 6
  • 57
  • 130
  • I am having the same problem. Even When I don't display the notification, it is calling didReceiveNotificationRequest and downloading the image twice!! Waste developer's backend money for Apple's bad design. Apple still takes 30% commission from the App Store. – coolcool1994 Sep 19 '20 at 18:52

1 Answers1

0

First from ios 10 you can present it with UNUserNotificationCenterDelegate delegate method

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

      completionHandler([.alert, .sound])


}

second it may be strange but you can share app state with userDefaults if you have app groups enabled with the extension

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • Using `NSUserDefaults` to share the app state sounds like an unreliable hack. Any other suggestions? – Manuel Jun 05 '18 at 19:58