if user leaves ios app, can i determine if they are interacting with another application before entering back...












0















I am looking to keep track of the amount of time users have spent in my application. I want to stop tracking this once the user interacts with any other application, but I do not want it to stop tracking this if the user locks their phone and re enters the application without interacting with anything else. is this possible in ios?










share|improve this question


















  • 1





    I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

    – Cool Guy CG
    Jan 2 at 17:10
















0















I am looking to keep track of the amount of time users have spent in my application. I want to stop tracking this once the user interacts with any other application, but I do not want it to stop tracking this if the user locks their phone and re enters the application without interacting with anything else. is this possible in ios?










share|improve this question


















  • 1





    I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

    – Cool Guy CG
    Jan 2 at 17:10














0












0








0








I am looking to keep track of the amount of time users have spent in my application. I want to stop tracking this once the user interacts with any other application, but I do not want it to stop tracking this if the user locks their phone and re enters the application without interacting with anything else. is this possible in ios?










share|improve this question














I am looking to keep track of the amount of time users have spent in my application. I want to stop tracking this once the user interacts with any other application, but I do not want it to stop tracking this if the user locks their phone and re enters the application without interacting with anything else. is this possible in ios?







ios






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 17:05









Zac HermanZac Herman

1




1








  • 1





    I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

    – Cool Guy CG
    Jan 2 at 17:10














  • 1





    I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

    – Cool Guy CG
    Jan 2 at 17:10








1




1





I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

– Cool Guy CG
Jan 2 at 17:10





I suggest you show us what you have done in that direction. But I would rather check if the user is still using the app and record the time spent before exit (whether you lock the phone or use another app), instead of the way you are suggesting.

– Cool Guy CG
Jan 2 at 17:10












2 Answers
2






active

oldest

votes


















1














Probably not, because your app is backgrounded and suspended in both situations and you have no means of distinguishing them.






share|improve this answer































    1














    "Interacts with any other application" is not something you can determine, and that's intentional. Even if you found some tricky way to achieve it, you should expect Apple to break it in the future because it's a privacy concern.



    Even more critically, "any other application" is one of those things that sounds very precise but is actually incredibly vague. Is interacting with a share sheet (which may be an extension to another app and occurs outside your process) "interacting with any other application?" How about a custom keyboard provided as an app extension? Is iPad multitasking "interacting with any other application?" How about receiving a phone call (i.e. Phone.app)? What if the phone call is answered, but the user comes right back to your app? If your app is running when the device powers off (intentionally or due to power loss), is that the same as "locks their phone?" There are lots and lots of corner cases.



    That said, you can detect a lot of the pieces you're describing via the application delegate (or the related notifications). You can tell when you resign active and go into the background, you can tell when the device is locked (via protectedDataWillBecomeUnavailableNotification). With that, and some heuristics around timing, you can determine a lot. For instance, if you resign active and then protected data immediately (or ~10s on older OSes) becomes unavailable, you know you were likely active when the user locked the device. Even more accurately, you can see that protected data become available immediately before your app becomes active.



    Almost certainly the want to deal with this by watching notifications (or app delegate methods) and the clock. If you resign active and then become active in a very short period of time, then there probably wasn't another app in there.



    One side note: protectedDataWillBecomeUnavailableNotification is generally only posted if device data protection is enabled, which requires the user to have a PIN. If the user has no PIN, then it may be a bit more difficult.






    share|improve this answer























      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%2f54010359%2fif-user-leaves-ios-app-can-i-determine-if-they-are-interacting-with-another-app%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Probably not, because your app is backgrounded and suspended in both situations and you have no means of distinguishing them.






      share|improve this answer




























        1














        Probably not, because your app is backgrounded and suspended in both situations and you have no means of distinguishing them.






        share|improve this answer


























          1












          1








          1







          Probably not, because your app is backgrounded and suspended in both situations and you have no means of distinguishing them.






          share|improve this answer













          Probably not, because your app is backgrounded and suspended in both situations and you have no means of distinguishing them.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 17:35









          mattmatt

          331k46541739




          331k46541739

























              1














              "Interacts with any other application" is not something you can determine, and that's intentional. Even if you found some tricky way to achieve it, you should expect Apple to break it in the future because it's a privacy concern.



              Even more critically, "any other application" is one of those things that sounds very precise but is actually incredibly vague. Is interacting with a share sheet (which may be an extension to another app and occurs outside your process) "interacting with any other application?" How about a custom keyboard provided as an app extension? Is iPad multitasking "interacting with any other application?" How about receiving a phone call (i.e. Phone.app)? What if the phone call is answered, but the user comes right back to your app? If your app is running when the device powers off (intentionally or due to power loss), is that the same as "locks their phone?" There are lots and lots of corner cases.



              That said, you can detect a lot of the pieces you're describing via the application delegate (or the related notifications). You can tell when you resign active and go into the background, you can tell when the device is locked (via protectedDataWillBecomeUnavailableNotification). With that, and some heuristics around timing, you can determine a lot. For instance, if you resign active and then protected data immediately (or ~10s on older OSes) becomes unavailable, you know you were likely active when the user locked the device. Even more accurately, you can see that protected data become available immediately before your app becomes active.



              Almost certainly the want to deal with this by watching notifications (or app delegate methods) and the clock. If you resign active and then become active in a very short period of time, then there probably wasn't another app in there.



              One side note: protectedDataWillBecomeUnavailableNotification is generally only posted if device data protection is enabled, which requires the user to have a PIN. If the user has no PIN, then it may be a bit more difficult.






              share|improve this answer




























                1














                "Interacts with any other application" is not something you can determine, and that's intentional. Even if you found some tricky way to achieve it, you should expect Apple to break it in the future because it's a privacy concern.



                Even more critically, "any other application" is one of those things that sounds very precise but is actually incredibly vague. Is interacting with a share sheet (which may be an extension to another app and occurs outside your process) "interacting with any other application?" How about a custom keyboard provided as an app extension? Is iPad multitasking "interacting with any other application?" How about receiving a phone call (i.e. Phone.app)? What if the phone call is answered, but the user comes right back to your app? If your app is running when the device powers off (intentionally or due to power loss), is that the same as "locks their phone?" There are lots and lots of corner cases.



                That said, you can detect a lot of the pieces you're describing via the application delegate (or the related notifications). You can tell when you resign active and go into the background, you can tell when the device is locked (via protectedDataWillBecomeUnavailableNotification). With that, and some heuristics around timing, you can determine a lot. For instance, if you resign active and then protected data immediately (or ~10s on older OSes) becomes unavailable, you know you were likely active when the user locked the device. Even more accurately, you can see that protected data become available immediately before your app becomes active.



                Almost certainly the want to deal with this by watching notifications (or app delegate methods) and the clock. If you resign active and then become active in a very short period of time, then there probably wasn't another app in there.



                One side note: protectedDataWillBecomeUnavailableNotification is generally only posted if device data protection is enabled, which requires the user to have a PIN. If the user has no PIN, then it may be a bit more difficult.






                share|improve this answer


























                  1












                  1








                  1







                  "Interacts with any other application" is not something you can determine, and that's intentional. Even if you found some tricky way to achieve it, you should expect Apple to break it in the future because it's a privacy concern.



                  Even more critically, "any other application" is one of those things that sounds very precise but is actually incredibly vague. Is interacting with a share sheet (which may be an extension to another app and occurs outside your process) "interacting with any other application?" How about a custom keyboard provided as an app extension? Is iPad multitasking "interacting with any other application?" How about receiving a phone call (i.e. Phone.app)? What if the phone call is answered, but the user comes right back to your app? If your app is running when the device powers off (intentionally or due to power loss), is that the same as "locks their phone?" There are lots and lots of corner cases.



                  That said, you can detect a lot of the pieces you're describing via the application delegate (or the related notifications). You can tell when you resign active and go into the background, you can tell when the device is locked (via protectedDataWillBecomeUnavailableNotification). With that, and some heuristics around timing, you can determine a lot. For instance, if you resign active and then protected data immediately (or ~10s on older OSes) becomes unavailable, you know you were likely active when the user locked the device. Even more accurately, you can see that protected data become available immediately before your app becomes active.



                  Almost certainly the want to deal with this by watching notifications (or app delegate methods) and the clock. If you resign active and then become active in a very short period of time, then there probably wasn't another app in there.



                  One side note: protectedDataWillBecomeUnavailableNotification is generally only posted if device data protection is enabled, which requires the user to have a PIN. If the user has no PIN, then it may be a bit more difficult.






                  share|improve this answer













                  "Interacts with any other application" is not something you can determine, and that's intentional. Even if you found some tricky way to achieve it, you should expect Apple to break it in the future because it's a privacy concern.



                  Even more critically, "any other application" is one of those things that sounds very precise but is actually incredibly vague. Is interacting with a share sheet (which may be an extension to another app and occurs outside your process) "interacting with any other application?" How about a custom keyboard provided as an app extension? Is iPad multitasking "interacting with any other application?" How about receiving a phone call (i.e. Phone.app)? What if the phone call is answered, but the user comes right back to your app? If your app is running when the device powers off (intentionally or due to power loss), is that the same as "locks their phone?" There are lots and lots of corner cases.



                  That said, you can detect a lot of the pieces you're describing via the application delegate (or the related notifications). You can tell when you resign active and go into the background, you can tell when the device is locked (via protectedDataWillBecomeUnavailableNotification). With that, and some heuristics around timing, you can determine a lot. For instance, if you resign active and then protected data immediately (or ~10s on older OSes) becomes unavailable, you know you were likely active when the user locked the device. Even more accurately, you can see that protected data become available immediately before your app becomes active.



                  Almost certainly the want to deal with this by watching notifications (or app delegate methods) and the clock. If you resign active and then become active in a very short period of time, then there probably wasn't another app in there.



                  One side note: protectedDataWillBecomeUnavailableNotification is generally only posted if device data protection is enabled, which requires the user to have a PIN. If the user has no PIN, then it may be a bit more difficult.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 17:56









                  Rob NapierRob Napier

                  204k28303431




                  204k28303431






























                      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%2f54010359%2fif-user-leaves-ios-app-can-i-determine-if-they-are-interacting-with-another-app%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

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas

                      Can't read property showImagePicker of undefined in react native iOS