I am working on an iOS app that sends the user a scheduled local notification every minute. However, I want to do this only when the phone is in use. As of now, it sends the notifications even when the phone is locked. Is there any way I can code for this in Swift? Thank you so much!
Asked
Active
Viewed 58 times
2
-
I don't think so that its possible in ios environment. – nabu Oct 16 '20 at 19:15
-
that might help: https://stackoverflow.com/questions/40171495/ios-can-i-detect-if-the-device-screen-is-on-off – adri567 Oct 16 '20 at 22:11
-
You need to observe `applicationDidBecomeActive` and `applicationDidEnterBackground` notifications. Turn them off when you enter the background and turn them on again when you become active. – DPrice Oct 17 '20 at 03:23