title: Incoming push notifications set alerts twice swift 4
body: <p>I'm implementing Push Notifications via Firebase Cloud Messaging, and when I get the alert on device it actually adverts twice, but on notifications list panel it appears just once as expected. I'm trying to sort this out but I'm new to Push notifications and I don't find where I did set a duplicate . I'm testing on an iPad 3 sunning iOs 9.3.5 . Can you see if I'm setting it up twice here in <code>didFinishLaunchingWithOptions</code>or where could I have set it twice?
  As always many thanks.</p>
  
  <p><code>didFinishLaunchingWithOptions</code>:</p>
  
  <pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -&gt; Bool {
          // Override point for customization after application launch.
  
          //  UI Theme selection
          if UserDefaults.standard.object(forKey: "Theme") != nil {
              Theme.selectedTheme = UserDefaults.standard.bool(forKey: "Theme") ? 1 : 2
          }
  
          // setting up Firebase
          FirebaseApp.configure()
          Messaging.messaging().delegate = self
  
  
          // setting up notification delegate
          if #available(iOS 10.0, *) {
              //iOS 10.0 and greater
              UNUserNotificationCenter.current().delegate = self
              let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  
              //Solicit permission from the user to receive notifications
              UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: { granted, error in
                  DispatchQueue.main.async {
                      if granted {
                          print("didFinishLaunchingWithOptions iOS 10: Successfully registered for APNs")
  
                      } else {
                          //Do stuff if unsuccessful...
                          print("didFinishLaunchingWithOptions iOO 10: Error in registering for APNs: \(String(describing: error))")
                      }
                  }
              })
  
          } else {
              //iOS 9
              let type: UIUserNotificationType = [UIUserNotificationType.badge, UIUserNotificationType.alert, UIUserNotificationType.sound]
  
              let setting = UIUserNotificationSettings(types: type, categories: nil)
              UIApplication.shared.registerUserNotificationSettings(setting)
              print("didFinishLaunchingWithOptions iOS 9: Successfully registered for APNs")
  
          }
          UIApplication.shared.registerForRemoteNotifications()
  
  
          //get application instance ID
          InstanceID.instanceID().instanceID { (result, error) in
              if let error = error {
                  print("didFinishLaunchingWithOptions: Error fetching remote instance ID: \(error)")
              } else if let result = result {
                  print("didFinishLaunchingWithOptions: Remote instance ID token: \(result.token)")
              }
          }
  
          // setting up remote control values
  
          let _ = RCValues.sharedInstance
          GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
  
  
          Crashlytics().debugMode = true
          Fabric.with([Crashlytics.self])
  
          //        // TODO: Move this to where you establish a user session
          //        self.logUser()
  
          return true
      }
  </code></pre>
  
  <p><code>didRegisterForRemoteNotificationsWithDeviceToken</code>:</p>
  
  <pre><code>func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
          let tokenParts = deviceToken.map { data -&gt; String in
              return String(format: "%02.2hhx", data)
          }
          let token = tokenParts.joined()
          print(" didRegisterForRemoteNotificationsWithDeviceToken : devcice token is: \(token)")
  
          if #available(iOS 10.0, *) {
              // For iOS 10 display notification (sent via APNS)
              UNUserNotificationCenter.current().delegate = self
              Messaging.messaging().apnsToken = deviceToken // mandatory!!
  
              let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
              UNUserNotificationCenter.current().requestAuthorization(
                  options: authOptions,
                  completionHandler: {_, _ in })
          } else {
              Messaging.messaging().apnsToken = deviceToken // mandatory!!
              let settings: UIUserNotificationSettings =
                  UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
              application.registerUserNotificationSettings(settings)
          }
  
      }
  </code></pre>
  
  <p><code>didReceiveRemoteNotification</code>:</p>
  
  <pre><code>    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                           fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
              print("didReceiveRemoteNotification with handler : Received new push Notification")
              // If you are receiving a notification message while your app is in the background,
              // this callback will not be fired till the user taps on the notification launching the application.
              // TODO: Handle data of notification
  
              // With swizzling disabled you must let Messaging know about the message, for Analytics
               Messaging.messaging().appDidReceiveMessage(userInfo)
  
              // Print message ID.
              if let messageID = userInfo[ fcmMessageIDKey] {
                  print("didReceiveRemoteNotification: Message ID: \(messageID)")
              }
  
              // Print full message.
              print("didReceiveRemoteNotification: Push notificationMessage is: \(userInfo)")
  
              completionHandler(UIBackgroundFetchResult.newData)
          }
  </code></pre>
  
  <p>console print at opening the notification: </p>
  
  <pre><code>didReceiveRemoteNotification with handler : Received new push Notification
  didReceiveRemoteNotification: Push notificationMessage is: [AnyHashable("google.c.a.c_id"): 1354763473839437035, AnyHashable("google.c.a.udt"): 0, AnyHashable("gcm.notification.sound2"): enabled, AnyHashable("gcm.n.e"): 1, AnyHashable("gcm.message_id"): 0:1558780267039787%6f9b8aab6f9b8aab, AnyHashable("google.c.a.ts"): 1558780266, AnyHashable("google.c.a.tc"): 1, AnyHashable("google.c.a.e"): 1, AnyHashable("google.c.a.c_l"): Test push , AnyHashable("aps"): {
      alert = "First push test";
      badge = 0;
      sound = enabled;
  }]
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Messaging][I-FCM019003] FIRMessagingAnalytics: Sending event: _cmp params: {
          campaign = 1354763473839437035;
          medium = notification;
          source = Firebase;
      }
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Messaging][I-FCM019005] FIRMessagingAnalytics: Sending event: _no params: {
          "_ndt" = 0;
          "_nmid" = 1354763473839437035;
          "_nmn" = "Test push ";
          "_nmt" = 1558780266;
      }
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Messaging][I-FCM006000] Received message missing local start time, dropped.
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023080] Setting user property. Name, value: firebase_last_notification (_ln), 1354763473839437035
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023087] User property set. Name, value: firebase_last_notification (_ln), 1354763473839437035
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023051] Logging event: origin, name, params: fcm, firebase_campaign (_cmp), {
          _cis = fcm_integration;
          campaign = 1354763473839437035;
          ga_event_origin (_o) = fcm;
          medium = notification;
          source = Firebase;
      }
  May 25 12:31:23  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023073] Debug mode is enabled. Marking event as debug and real-time. Event name, parameters: firebase_campaign (_cmp), {
          _cis = fcm_integration;
          campaign = 1354763473839437035;
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          medium = notification;
          source = Firebase;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS033003] Scheduling user engagement timer
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002002] Engagement timer scheduled to fire in approx. (s): 3600
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023072] Event logged. Event name, event params: firebase_campaign (_cmp), {
          _cis = fcm_integration;
          campaign = 1354763473839437035;
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          medium = notification;
          source = Firebase;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): -0.09409010410308838
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023028] Upload task scheduled to be executed in approx. (s): -0.09409010410308838
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023051] Logging event: origin, name, params: fcm, notification_open (_no), {
          ga_event_origin (_o) = fcm;
          message_device_time (_ndt) = 0;
          message_id (_nmid) = 1354763473839437035;
          message_name (_nmn) = Test push ;
          message_time (_nmt) = 1558780266;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023073] Debug mode is enabled. Marking event as debug and real-time. Event name, parameters: notification_open (_no), {
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          message_device_time (_ndt) = 0;
          message_id (_nmid) = 1354763473839437035;
          message_name (_nmn) = Test push ;
          message_time (_nmt) = 1558780266;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023072] Event logged. Event name, event params: notification_open (_no), {
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          message_device_time (_ndt) = 0;
          message_id (_nmid) = 1354763473839437035;
          message_name (_nmn) = Test push ;
          message_time (_nmt) = 1558780266;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023027] Do not schedule an upload task. Task already exists. Will be executed in seconds: -0.3860381841659546
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002001] Measurement timer fired
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002003] Measurement timer canceled
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023033] Starting data upload
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: firebase_campaign (_cmp), {
          _cis = fcm_integration;
          campaign = 1354763473839437035;
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          medium = notification;
          source = Firebase;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023105] Event is not subject to real-time event count daily limit. Marking an event as real-time. Event name, parameters: notification_open (_no), {
          firebase_debug (_dbg) = 1;
          ga_event_origin (_o) = fcm;
          ga_realtime (_r) = 1;
          message_device_time (_ndt) = 0;
          message_id (_nmid) = 1354763473839437035;
          message_name (_nmn) = Test push ;
          message_time (_nmt) = 1558780266;
      }
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS012018] Saving bundle. size (bytes): 543
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023116] Bundle added to the upload queue. BundleID, timestamp (ms): 81, 1558780283193
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023038] Uploading events. Elapsed time since last successful upload (s): 275.0853600502014
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023039] Measurement data sent to network. Timestamp (ms), data: 1558780284672, &lt;APMPBMeasurementBatch: 0x16ef3490&gt;
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS900000] Uploading data. Host: https://app-measurement.com/a
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS901006] Received SSL challenge for host. Host: https://app-measurement.com/a
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023044] Successful upload. Got network response. Code, size: 204, 0
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002002] Measurement timer scheduled to fire in approx. (s): -0.7099969387054443
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023028] Upload task scheduled to be executed in approx. (s): -0.7099969387054443
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS023024] No data to upload. Upload task will not be scheduled
  May 25 12:31:24  fix-it shop[406] &lt;Debug&gt;: 5.20.0 - [Firebase/Analytics][I-ACS002003] Measurement timer canceled
  </code></pre>