IOS App to know when app is locked or using another appdetect screen unlock events in IOS Swifthow to check if the iOS device is locked/unlocked using Swift?How to change the name of an iOS app?How to link to apps on the app storeHow can I make a UITextField move up when the keyboard is present - on starting to edit?NSTimer crash with EXC_BAD_ACCESS on Iphone when invalidateHow do I check if a string contains another string in Objective-C?Swipe to answer local notification doesn't always bring app to foregroundHandling push notification when app is in background and device is lockedNotificationCenter stops working when the screen is lockedUse UNNotificationRequest (UserNotificationFramework) for data only local notification on iOSHow to send local notification to user when they leave the app IOS

How to calculate the node voltages for this circuit using the voltage divider rule

Reducing the white spacing

Position of past participle and extent of the Verbklammer

Why does this rising edge detector using a capacitor and a resistor work?

Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?

Out of scope work duties and resignation

How can I get a job without pushing my family's income into a higher tax bracket?

Can you complete the sequence?

Verb "geeitet" in an old scientific text

Shantae Dance Matching

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

Make some Prime Squares!

Why are prions in animal diets not destroyed by the digestive system?

Can Infinity Stones be retrieved more than once?

Multi-channel audio upsampling interpolation

What property of a BJT transistor makes it an amplifier?

Missing Piece of Pie - Can you find it?

Would Hubble Space Telescope improve black hole image observed by EHT if it joined array of telesopes?

What was the design of the Macintosh II's MMU replacement?

String won't reverse using reverse_copy

Point of the the Dothraki's attack in GoT S8E3?

How adjust and align properly different equations

As matter approaches a black hole, does it speed up?

Why isn't nylon as strong as kevlar?



IOS App to know when app is locked or using another app


detect screen unlock events in IOS Swifthow to check if the iOS device is locked/unlocked using Swift?How to change the name of an iOS app?How to link to apps on the app storeHow can I make a UITextField move up when the keyboard is present - on starting to edit?NSTimer crash with EXC_BAD_ACCESS on Iphone when invalidateHow do I check if a string contains another string in Objective-C?Swipe to answer local notification doesn't always bring app to foregroundHandling push notification when app is in background and device is lockedNotificationCenter stops working when the screen is lockedUse UNNotificationRequest (UserNotificationFramework) for data only local notification on iOSHow to send local notification to user when they leave the app IOS






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















Trying to figure out, with my app, how to make the app know when the phone is locked or when the app is minimized and using another app.



This is what i have so far:



//warning notification
func warningNotification()
let content = UNMutableNotificationContent()
content.title = "Go back to app immediately to prevent"
// content.body = publictime
// print("Notification timer(content.body)")
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
repeats: false)

let requestIdentifier = "demoNotification"
let request = UNNotificationRequest(identifier: requestIdentifier,
content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request,
withCompletionHandler: (error) in
// Handle error
)











share|improve this question

















  • 1





    Check your app's background Stage on appDelegate

    – eddwinpaz
    Mar 23 at 2:15












  • Possible duplicate.. stackoverflow.com/questions/31429800/…

    – Mocha
    Mar 23 at 5:51

















-2















Trying to figure out, with my app, how to make the app know when the phone is locked or when the app is minimized and using another app.



This is what i have so far:



//warning notification
func warningNotification()
let content = UNMutableNotificationContent()
content.title = "Go back to app immediately to prevent"
// content.body = publictime
// print("Notification timer(content.body)")
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
repeats: false)

let requestIdentifier = "demoNotification"
let request = UNNotificationRequest(identifier: requestIdentifier,
content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request,
withCompletionHandler: (error) in
// Handle error
)











share|improve this question

















  • 1





    Check your app's background Stage on appDelegate

    – eddwinpaz
    Mar 23 at 2:15












  • Possible duplicate.. stackoverflow.com/questions/31429800/…

    – Mocha
    Mar 23 at 5:51













-2












-2








-2








Trying to figure out, with my app, how to make the app know when the phone is locked or when the app is minimized and using another app.



This is what i have so far:



//warning notification
func warningNotification()
let content = UNMutableNotificationContent()
content.title = "Go back to app immediately to prevent"
// content.body = publictime
// print("Notification timer(content.body)")
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
repeats: false)

let requestIdentifier = "demoNotification"
let request = UNNotificationRequest(identifier: requestIdentifier,
content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request,
withCompletionHandler: (error) in
// Handle error
)











share|improve this question














Trying to figure out, with my app, how to make the app know when the phone is locked or when the app is minimized and using another app.



This is what i have so far:



//warning notification
func warningNotification()
let content = UNMutableNotificationContent()
content.title = "Go back to app immediately to prevent"
// content.body = publictime
// print("Notification timer(content.body)")
content.badge = 1

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
repeats: false)

let requestIdentifier = "demoNotification"
let request = UNNotificationRequest(identifier: requestIdentifier,
content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request,
withCompletionHandler: (error) in
// Handle error
)








ios swift xcode






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 22:10









swstrau118swstrau118

56512




56512







  • 1





    Check your app's background Stage on appDelegate

    – eddwinpaz
    Mar 23 at 2:15












  • Possible duplicate.. stackoverflow.com/questions/31429800/…

    – Mocha
    Mar 23 at 5:51












  • 1





    Check your app's background Stage on appDelegate

    – eddwinpaz
    Mar 23 at 2:15












  • Possible duplicate.. stackoverflow.com/questions/31429800/…

    – Mocha
    Mar 23 at 5:51







1




1





Check your app's background Stage on appDelegate

– eddwinpaz
Mar 23 at 2:15






Check your app's background Stage on appDelegate

– eddwinpaz
Mar 23 at 2:15














Possible duplicate.. stackoverflow.com/questions/31429800/…

– Mocha
Mar 23 at 5:51





Possible duplicate.. stackoverflow.com/questions/31429800/…

– Mocha
Mar 23 at 5:51












2 Answers
2






active

oldest

votes


















0














Take a look at the default functions inside your AppDelegate. In your situation you might be interested in applicationWillResignActive, applicationDidEnterBackground, or applicationWillTerminate.






share|improve this answer






























    0














    There are a few ways to achieve these things; however, currently to my knowledge, it is not possible to know for sure if a user is now using another app. You can tell if a user has put your app into the background. Once an app is in the background, they are either going to the home screen or opening another app.



    You can achieve this by looking at the function applicationDidEnterBackground(_:)



    optional func applicationDidEnterBackground(_ application: UIApplication)


    Apple Docs for DidEnterBackground



    You can access this in the App Delegate or register for notification if you are putting your code in another class or view controller.



    Screen lock on stackoverflow



    More screen lock on stackoverflow



    As for detecting if the phone has been locked, there are a few posts already on StackOverflow about this. However, looking at these it may not be possible with Native code, and even the private API's they suggest do not seem to work very well.



    You should be able to achieve what you need using the delegate methods Apple provides. Take a more in-depth look at the docs. If you let me know why you need access to these things I always happy to give more advice as it is not 100% clear from your code.



    More Apple Docs






    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%2f55308427%2fios-app-to-know-when-app-is-locked-or-using-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









      0














      Take a look at the default functions inside your AppDelegate. In your situation you might be interested in applicationWillResignActive, applicationDidEnterBackground, or applicationWillTerminate.






      share|improve this answer



























        0














        Take a look at the default functions inside your AppDelegate. In your situation you might be interested in applicationWillResignActive, applicationDidEnterBackground, or applicationWillTerminate.






        share|improve this answer

























          0












          0








          0







          Take a look at the default functions inside your AppDelegate. In your situation you might be interested in applicationWillResignActive, applicationDidEnterBackground, or applicationWillTerminate.






          share|improve this answer













          Take a look at the default functions inside your AppDelegate. In your situation you might be interested in applicationWillResignActive, applicationDidEnterBackground, or applicationWillTerminate.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 3:13









          HamerHamer

          8921530




          8921530























              0














              There are a few ways to achieve these things; however, currently to my knowledge, it is not possible to know for sure if a user is now using another app. You can tell if a user has put your app into the background. Once an app is in the background, they are either going to the home screen or opening another app.



              You can achieve this by looking at the function applicationDidEnterBackground(_:)



              optional func applicationDidEnterBackground(_ application: UIApplication)


              Apple Docs for DidEnterBackground



              You can access this in the App Delegate or register for notification if you are putting your code in another class or view controller.



              Screen lock on stackoverflow



              More screen lock on stackoverflow



              As for detecting if the phone has been locked, there are a few posts already on StackOverflow about this. However, looking at these it may not be possible with Native code, and even the private API's they suggest do not seem to work very well.



              You should be able to achieve what you need using the delegate methods Apple provides. Take a more in-depth look at the docs. If you let me know why you need access to these things I always happy to give more advice as it is not 100% clear from your code.



              More Apple Docs






              share|improve this answer



























                0














                There are a few ways to achieve these things; however, currently to my knowledge, it is not possible to know for sure if a user is now using another app. You can tell if a user has put your app into the background. Once an app is in the background, they are either going to the home screen or opening another app.



                You can achieve this by looking at the function applicationDidEnterBackground(_:)



                optional func applicationDidEnterBackground(_ application: UIApplication)


                Apple Docs for DidEnterBackground



                You can access this in the App Delegate or register for notification if you are putting your code in another class or view controller.



                Screen lock on stackoverflow



                More screen lock on stackoverflow



                As for detecting if the phone has been locked, there are a few posts already on StackOverflow about this. However, looking at these it may not be possible with Native code, and even the private API's they suggest do not seem to work very well.



                You should be able to achieve what you need using the delegate methods Apple provides. Take a more in-depth look at the docs. If you let me know why you need access to these things I always happy to give more advice as it is not 100% clear from your code.



                More Apple Docs






                share|improve this answer

























                  0












                  0








                  0







                  There are a few ways to achieve these things; however, currently to my knowledge, it is not possible to know for sure if a user is now using another app. You can tell if a user has put your app into the background. Once an app is in the background, they are either going to the home screen or opening another app.



                  You can achieve this by looking at the function applicationDidEnterBackground(_:)



                  optional func applicationDidEnterBackground(_ application: UIApplication)


                  Apple Docs for DidEnterBackground



                  You can access this in the App Delegate or register for notification if you are putting your code in another class or view controller.



                  Screen lock on stackoverflow



                  More screen lock on stackoverflow



                  As for detecting if the phone has been locked, there are a few posts already on StackOverflow about this. However, looking at these it may not be possible with Native code, and even the private API's they suggest do not seem to work very well.



                  You should be able to achieve what you need using the delegate methods Apple provides. Take a more in-depth look at the docs. If you let me know why you need access to these things I always happy to give more advice as it is not 100% clear from your code.



                  More Apple Docs






                  share|improve this answer













                  There are a few ways to achieve these things; however, currently to my knowledge, it is not possible to know for sure if a user is now using another app. You can tell if a user has put your app into the background. Once an app is in the background, they are either going to the home screen or opening another app.



                  You can achieve this by looking at the function applicationDidEnterBackground(_:)



                  optional func applicationDidEnterBackground(_ application: UIApplication)


                  Apple Docs for DidEnterBackground



                  You can access this in the App Delegate or register for notification if you are putting your code in another class or view controller.



                  Screen lock on stackoverflow



                  More screen lock on stackoverflow



                  As for detecting if the phone has been locked, there are a few posts already on StackOverflow about this. However, looking at these it may not be possible with Native code, and even the private API's they suggest do not seem to work very well.



                  You should be able to achieve what you need using the delegate methods Apple provides. Take a more in-depth look at the docs. If you let me know why you need access to these things I always happy to give more advice as it is not 100% clear from your code.



                  More Apple Docs







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 4:29









                  AlexanderKaranAlexanderKaran

                  214




                  214



























                      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%2f55308427%2fios-app-to-know-when-app-is-locked-or-using-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

                      How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                      Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?