Local notification pull into background function triggering












0















when I terminate my app into twice tap on home button then how can I call my function in background service on swift 4.
because I work on local push notification , after API calling then getting data and that's data put into notification.










share|improve this question



























    0















    when I terminate my app into twice tap on home button then how can I call my function in background service on swift 4.
    because I work on local push notification , after API calling then getting data and that's data put into notification.










    share|improve this question

























      0












      0








      0








      when I terminate my app into twice tap on home button then how can I call my function in background service on swift 4.
      because I work on local push notification , after API calling then getting data and that's data put into notification.










      share|improve this question














      when I terminate my app into twice tap on home button then how can I call my function in background service on swift 4.
      because I work on local push notification , after API calling then getting data and that's data put into notification.







      swift notifications local






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 12:33









      Nupendra VermaNupendra Verma

      14




      14
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
          If you want to execute code when the app terminates, use applicationWillTerminate(_:).



          So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):



          class AppDelegate: UIResponder, UIApplicationDelegate {

          func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
          yourGoToBackgroundFunction()
          }

          func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          yourSaveDataFunction()
          }

          func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          yourSaveDataFunction()
          }
          }





          share|improve this answer


























          • Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

            – Nupendra Verma
            Nov 26 '18 at 7:52













          • Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

            – Eric
            Nov 28 '18 at 16:51











          • yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

            – Nupendra Verma
            Nov 29 '18 at 12:37











          • have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

            – Eric
            Nov 30 '18 at 15:48











          • I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

            – Nupendra Verma
            Dec 1 '18 at 9:37











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458192%2flocal-notification-pull-into-background-function-triggering%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
          If you want to execute code when the app terminates, use applicationWillTerminate(_:).



          So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):



          class AppDelegate: UIResponder, UIApplicationDelegate {

          func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
          yourGoToBackgroundFunction()
          }

          func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          yourSaveDataFunction()
          }

          func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          yourSaveDataFunction()
          }
          }





          share|improve this answer


























          • Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

            – Nupendra Verma
            Nov 26 '18 at 7:52













          • Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

            – Eric
            Nov 28 '18 at 16:51











          • yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

            – Nupendra Verma
            Nov 29 '18 at 12:37











          • have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

            – Eric
            Nov 30 '18 at 15:48











          • I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

            – Nupendra Verma
            Dec 1 '18 at 9:37
















          0














          I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
          If you want to execute code when the app terminates, use applicationWillTerminate(_:).



          So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):



          class AppDelegate: UIResponder, UIApplicationDelegate {

          func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
          yourGoToBackgroundFunction()
          }

          func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          yourSaveDataFunction()
          }

          func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          yourSaveDataFunction()
          }
          }





          share|improve this answer


























          • Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

            – Nupendra Verma
            Nov 26 '18 at 7:52













          • Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

            – Eric
            Nov 28 '18 at 16:51











          • yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

            – Nupendra Verma
            Nov 29 '18 at 12:37











          • have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

            – Eric
            Nov 30 '18 at 15:48











          • I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

            – Nupendra Verma
            Dec 1 '18 at 9:37














          0












          0








          0







          I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
          If you want to execute code when the app terminates, use applicationWillTerminate(_:).



          So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):



          class AppDelegate: UIResponder, UIApplicationDelegate {

          func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
          yourGoToBackgroundFunction()
          }

          func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          yourSaveDataFunction()
          }

          func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          yourSaveDataFunction()
          }
          }





          share|improve this answer















          I am not entirely sure this is what you mean, but if you want to call a function/do something right before your app enters the background(what happens when someone double clicks the home button) you can use the default applicationWillResignActive(_:) or applicationDidEnterBackground(_:) function in the AppDelegate class. See the apple docs for more information about app states and functions.
          If you want to execute code when the app terminates, use applicationWillTerminate(_:).



          So in AppDelegate.swift(I deliberately left the original Xcode default comment in for clarification):



          class AppDelegate: UIResponder, UIApplicationDelegate {

          func applicationWillResignActive(_ application: UIApplication) {
          // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
          // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
          yourGoToBackgroundFunction()
          }

          func applicationDidEnterBackground(_ application: UIApplication) {
          // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
          // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
          yourSaveDataFunction()
          }

          func applicationWillTerminate(_ application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
          yourSaveDataFunction()
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 22 '18 at 15:06

























          answered Nov 24 '18 at 13:01









          EricEric

          832419




          832419













          • Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

            – Nupendra Verma
            Nov 26 '18 at 7:52













          • Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

            – Eric
            Nov 28 '18 at 16:51











          • yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

            – Nupendra Verma
            Nov 29 '18 at 12:37











          • have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

            – Eric
            Nov 30 '18 at 15:48











          • I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

            – Nupendra Verma
            Dec 1 '18 at 9:37



















          • Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

            – Nupendra Verma
            Nov 26 '18 at 7:52













          • Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

            – Eric
            Nov 28 '18 at 16:51











          • yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

            – Nupendra Verma
            Nov 29 '18 at 12:37











          • have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

            – Eric
            Nov 30 '18 at 15:48











          • I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

            – Nupendra Verma
            Dec 1 '18 at 9:37

















          Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

          – Nupendra Verma
          Nov 26 '18 at 7:52







          Thank you sir.. I want to call API function(Alamofire) into the applicationDidEnterBackground(_:) to but I can't. so if any solution please suggest me.

          – Nupendra Verma
          Nov 26 '18 at 7:52















          Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

          – Eric
          Nov 28 '18 at 16:51





          Please eleborate and clarify your question then. What function are you trying to call? What does not work? I can't help you when you don't give me any details.

          – Eric
          Nov 28 '18 at 16:51













          yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

          – Nupendra Verma
          Nov 29 '18 at 12:37





          yes sir, "my requirement is to create broadcast receiver like android service." so when I terminate my app completely but after terminating app I want to automatically call a function into background like(Broadcast Receiver 'Android') and this function is post few data to my server and get JSON response and this JSON data I want to use in Local Notification and show it Device.

          – Nupendra Verma
          Nov 29 '18 at 12:37













          have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

          – Eric
          Nov 30 '18 at 15:48





          have you tried putting it in applicationWillResignActive? I think it should be there instead of applicationDidEnterBackground

          – Eric
          Nov 30 '18 at 15:48













          I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

          – Nupendra Verma
          Dec 1 '18 at 9:37





          I try to write my code in both applicationWillResignActive and applicationDidEnterBackground block but this function run my code only inactive state doesn't run on terminate state.

          – Nupendra Verma
          Dec 1 '18 at 9:37




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458192%2flocal-notification-pull-into-background-function-triggering%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ottavio Pratesi

          Tricia Helfer

          15 giugno