Vanar 3 Posted December 5 Tell me, how can I programmatically control the screen brightness under iOS? Share this post Link to post
Hans♫ 76 Posted December 5 To increase the chances for a positive response, I would recommend to first check if its possible at all with XCode and Objective-C. If it's possible there then its usually also possible in Delphi, and then you can begin figuring out how its done and eventually ask about it here. 1 Share this post Link to post
Vanar 3 Posted December 5 3 hours ago, Hans♫ said: To increase the chances for a positive response, I would recommend to first check if its possible at all with XCode and Objective-C. If it's possible there then its usually also possible in Delphi, and then you can begin figuring out how its done and eventually ask about it here. I know for sure that it is possible. In most applications from stores, when calling (showing) QR, the brightness of the iPhone screen increases ... Share this post Link to post
Lajos Juhász 295 Posted December 5 This was written by Copilot. I can not test the code as I do not have the iOS units installed on my system. To change the screen brightness on iOS using Delphi, you can use the UIScreen class from the iOS API. Here's a basic example of how you can achieve this: 1. Import the necessary iOS units: uses iOSapi.UIKit, iOSapi.Foundation; 1. Set the screen brightness: procedure SetScreenBrightness(Brightness: CGFloat); begin UIScreen.mainScreen.setBrightness(Brightness); end; 1. Call the procedure with the desired brightness level: begin SetScreenBrightness(0.5); // Set brightness to 50% end; In this example, UIScreen.mainScreen.setBrightness is used to set the brightness level. The brightness value should be between 0.0 (minimum brightness) and 1.0 (maximum brightness)https://www.reddit.com/r/iOSProgramming/comments/whtu5q/is_there_a_way_to_control_screen_brightness/https://forums.developer.apple.com/forums/thread/717234. Would you like more details on integrating this into a full application? 1 Share this post Link to post
Dave Nottage 561 Posted December 5 6 hours ago, Vanar said: Tell me, how can I programmatically control the screen brightness under iOS? uses iOSapi.Helpers; function GetBrightness: Single; begin Result := TiOSHelper.MainScreen.brightness; end; procedure SetBrightness(const AValue: Single); begin if (AValue >= 0) and (AValue <= 1) then TiOSHelper.MainScreen.setBrightness(AValue); end; 1 Share this post Link to post
Vanar 3 Posted December 6 Thanks everyone! I applied Dave's solution. Thread closed. 1 Share this post Link to post
Hans♫ 76 Posted December 11 On 12/5/2024 at 6:51 PM, Vanar said: I know for sure that it is possible. In most applications from stores, when calling (showing) QR, the brightness of the iPhone screen increases ... Ok, thats great. So let me elaborate: When you have found out what native functions are used in Objective-C to get the wanted result, then you can search the source code of Delphi for those functions. This will tell you exactly what function to call in Delphi to access the feature. Its of course nice to be able to get help here in DelphiPraxis, but its even better if you know how to find the solution on your own - and its much faster 🙂 Share this post Link to post
sjordi 42 Posted Thursday at 12:48 PM (edited) Jut for the fun, I programmed a little app for my daughter when she was young, to let her know whether she could wake up (day) or not (night), keep silent or not in the morning... Meaning she doesn't wake us up at 5am on Sundays, but has to wait til 7... To adjust contrast I just put a TRectangle filling the form and added a ContrastEffect to it. Then adjusting ContrastEffect.Brightness values depending on time It was managing contrast just for the app on the desk tablet, not the entire iPad or Android tablet. Edited Thursday at 12:48 PM by sjordi Share this post Link to post
Rollo62 538 Posted Thursday at 05:55 PM (edited) 5 hours ago, sjordi said: To adjust contrast I just put a TRectangle filling the form and added a ContrastEffect to it. Nice idea. I understand this is for your personal phone, that will be fine, but if this is for the AppStore and the apps whole purpose is like this, then I'm afraid the reviewer will have a few questions ... Edited Thursday at 05:55 PM by Rollo62 Share this post Link to post
sjordi 42 Posted Thursday at 08:06 PM (edited) Of course the app had something else: images with a kid saying to shush with his finger on his mouth, the moon, the sun to explain a toddler what time of day it is. Actually, the brightness was just controlling the background to dim the screen at night. Could make it a bit more configurable and actually have it in the AppStore for others. Was intended as a sleep trainer like the image here: eyes closed you keep sleeping, eyes open, you can disturb us. Edited Thursday at 08:11 PM by sjordi 2 Share this post Link to post