2017-11-14 4 views
1

ich Push-Benachrichtigung auf mein Projekt integriert haben und aus irgendeinem Grund das Banner erscheint, wenn ich im Hintergrund Stimmung bin und nicht, wenn ich im Vordergrund bin. Ich bin sicher, ich habe etwas verpasst, mein Code wie unten. Jede Hilfe würde sehr schätzen.PushNotification Banner zeigt nicht in ios 10.3

Dies wird jedes Mal aufgerufen, wenn ich eine Benachrichtigung erhält, obwohl es im Vordergrund oder Hintergrund ausgeführt wird. Daher wird das Stapelsymbol aktualisiert.

func application(_ application: UIApplication, 
         didReceiveRemoteNotification userInfo: [AnyHashable : Any], 
         fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) 
     { 

      print("Recived: \(userInfo)") 

      completionHandler(.newData) 

      self.onPushRecieved = MP3ViewController().catchPushNotifications 
      let notification = JSON(userInfo) 
      print(notification) 

      let mediaId = (notification["media_id"]).stringValue 
      print(mediaId) 
      var badgeCount = 0 
      var pushAvailable = false 


      if let pushCount = UserDefaults.standard.value(forKey: "PUSH_COUNT"){ 
       badgeCount = pushCount as! Int 
       print(badgeCount) 
       badgeCount = badgeCount + 1 
       UIApplication.shared.applicationIconBadgeNumber = badgeCount 
      } 

      print(badgeCount) 
      UserDefaults.standard.setValue(badgeCount, forKey: "PUSH_COUNT") 
      UserDefaults.standard.synchronize() 

      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
      print(isOnBackGround) 
      if isOnBackGround { 
       if mediaId != nil{ 
        DispatchQueue.main.async { 
         let mP3ViewController = storyboard.instantiateViewController(withIdentifier:"MP3ViewController") as! MP3ViewController 
         mP3ViewController.media_ID = mediaId 
         self.navigationController?.pushViewController(mP3ViewController, animated:true) 
         self.isOnBackGround = false 

        } 

       } 
      }else{ 
       print("Running on foreground") 

      } 

     } 
    } 
+1

Das UNUserNotificationCenterDelegate Protokoll definiert Methoden für Benachrichtigungen empfangen und Aktionen Handhabung. Also was ist die Art und Weise individuelle Banner – danu

+0

@danu zu behandeln Wo die 'delegate' Methoden der' UNUserNotificationCenterDelegate' ist? – Mannopson

Antwort

2

Möglicherweise möchten Sie die folgende Funktion implementieren, zB:

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

dieser Delegierten: UNUserNotificationCenterDelegate

Verwandte Themen