Remote Push Notification

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Remote Push Notification

    Hey,

    bin gerade auf das Forum gestoßen und habe ein Problem.

    Bei Google habe ich leider nichts gefunden, dass mir weiterhilft.

    Bei meiner App soll ein externes Programm auf einem Server dafür sorgen, dass die App eine gewisse URL aufruft.
    Ich habe hier an Remote Push Notification gedacht und komme auch soweit, dass im Hintergrund und im Vordergrund die App das macht was sie soll (den http request).

    Mein Problem ist jetzt nur, dass wenn ich die App in der App Ansicht nach oben schiebe (Doppelklick auf den Home Button) die Notification nur noch angezeigt wird aber keinerlei Code mehr ausführt.


    Würde mich freuen, wenn ihr hier helfen könnt.

    Danke
    Drabur
  • Danke für die schnelle Antwort :D


    Quellcode

    1. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) {
    2. URLSession.shared.dataTask(with: URL(string: "http://10.1.1.11/app.php")!) {
    3. data, response, error in
    4. print( data )
    5. completionHandler(.newData)
    6. }.resume()
    7. }
    Am Rechner ist Wireshark an. Da kommt nichts an.
  • MCDan schrieb:

    Wenn die App bereits aktiv ist, wenn die Remote Notification eintrifft, dann sollte (ab iOS 10) die Methode userNotificationCenter(_:willPresent:withCompletionHandler:) aufgerufen werden.


    Die App muss natürlich vorher ein Delegate im UNUserNotificationCenter setzen.
    Ich hab in beiden mal den gleichen Code eingesetzt.

    Quellcode

    1. func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    2. URLSession.shared.dataTask(with: URL(string: "http://10.1.1.11/app.php")!) {
    3. data, response, error in
    4. print( data )
    5. }.resume()
    6. }
    7. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) {
    8. URLSession.shared.dataTask(with: URL(string: "http://10.1.1.11/app.php")!) {
    9. data, response, error in
    10. print( data )
    11. completionHandler(.newData)
    12. }.resume()
    13. }
    Alles anzeigen


    Das Delegate im UNUserNotificationCenter habe ich denke ich mal gemacht. (Bin neu bei iOS Apps bzw. Swift.)
    Leider gehts trotzdem nicht wenn die App beendet ist.

    Quellcode

    1. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    2. UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
    3. print("request notification permission")
    4. }
    5. UIApplication.shared.registerForRemoteNotifications()
    6. return true
    7. }
    Ich nutze Pusher V.0.7.5 ist es möglich das es daran liegt?