๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŽ iOS/iOS Application

[iOS] ์ฝ”๋“œ๋กœ ํ™”๋ฉด ๋ฐ๊ธฐ ์กฐ์ ˆ, ์ž๋™ ์ž ๊ธˆ ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™” (์ ˆ์ „๋ชจ๋“œ) ํ•˜๊ธฐ(Swift, Objective-c)

iOS ์ฝ”๋“œ๋กœ ํ™”๋ฉด ๋ฐ๊ธฐ ์กฐ์ ˆ, ์ž๋™ ์ž ๊ธˆ ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™” (์ ˆ์ „๋ชจ๋“œ) ํ•˜๊ธฐ

 

 

 

์˜ค๋Š˜์€ ์•„์ดํฐ์˜ ํ™”๋ฉด์„ ์ œ์–ดํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋จผ์ €, ์š”์ฆ˜๊ฐ™์ด QR์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋‚ ๋„ ์—†์„๊ฑฐ์—์š”....

ํ™”๋ฉด์ด ์–ด๋‘์šฐ๋ฉด QR์ธ์‹์ด ์ž˜ ์•ˆ๋˜๋ฏ€๋กœ QR ์‹คํ–‰์‹œ ํ™”๋ฉด์ด ์ตœ๋Œ€๋กœ ๋ฐ๋„๋ก ์ œ์–ดํ•˜๋Š” ๋กœ์ง์ด ํ•„์š”ํ•˜๊ฒ ์ฃ ~?

์ตœ๋Œ€ ๋ฐ๊ธฐ, ๋ฐ๊ธฐ๋ฅผ ์กฐ์ ˆํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ, ์ ˆ์ „๋ชจ๋“œ๋ฅผ ๋น„ํ™œ์„ฑํ™”์‹œํ‚ค๋ฉด ํ™”๋ฉด์ด ์ž๋™์œผ๋กœ ์ž ๊ธˆ ๋˜์ง€ ์•Š๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


โœ”๏ธ 1. ํ™”๋ฉด ๋ฐ๊ธฐ ์กฐ์ ˆํ•˜๊ธฐ

UIScreen.main.brightness ๋กœ ํ™”๋ฉด ๋ฐ๊ธฐ๋ฅผ ์กฐ์ ˆํ•ฉ๋‹ˆ๋‹ค.

์ด๋•Œ, birghtness๋Š” floatํ˜•์œผ๋กœ 0.0~1.0์˜ ๊ฐ’์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค. ์ตœ๋Œ€์˜ ๋ฐ๊ธฐ๋ฅผ ํ•˜๋ ค๋ฉด 1.0์œผ๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํ˜„์žฌ ๋ฐ๊ธฐ๋ฅผ ๋ฐ›์•„์™€ ์ตœ๋Œ€(1.0)์ด ์•„๋‹Œ๊ฒฝ์šฐ ์„ค์ •ํ•˜๋Š” ๋กœ์ง์„ ์„ธ์šฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค~!

๊ณต์‹ ๋ฌธ์„œ์— ๋”ฐ๋ฅด๋ฉด ์•ฑ์—์„œ ์กฐ์ ˆํ•œ ๋ฐ๊ธฐ๋Š” ๋””๋ฐ”์ด์Šค๊ฐ€ ์ž ๊ธˆ๋˜๊ธฐ ์ „๊นŒ์ง€๋งŒ ํšจ๊ณผ๊ฐ€ ์œ ์ง€๋˜๊ณ , ์ž ๊ธˆ ์ดํ›„์—๋Š” ์›๋ž˜ ์„ค์ •์œผ๋กœ ๋˜๋Œ์•„๊ฐ„๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

Swift

//Get brightness
let brightess = UIScreen.main.brightness

//Set brightness
let inputBrightness: CGFloat
...
UIScreen.screen.brightness = inputBrightness

//์ตœ๋Œ€ ๋ฐ๊ธฐ๋กœ ์„ธํŒ…
UIScreen.screen.brightness = 1.0

Objective-C

//Get brightness
CGFloat brightess = [[UIScreen mainScreen] brightness];
    
//Set brightness
@property float *inputBrightness;
...
[[UIScreen mainScreen] setBrightness: inputBrightness];

//์ตœ๋Œ€ ๋ฐ๊ธฐ๋กœ ์„ค์ •
[[UIScreen mainScreen] setBrightness:1.0];

 

 

 


โœ”๏ธ 2. ์ž๋™ ์ž ๊ธˆ ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™” (์ ˆ์ „๋ชจ๋“œ) - ํ™”๋ฉด ๊บผ์ง ๋ฐฉ์ง€ํ•˜๊ธฐ

UIApplication.shared.isIdleTimerDisabled ๋กœ ํ™”๋ฉด ๊บผ์ง์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.

์ ˆ์ „๋ชจ๋“œ ๋น„ํ™œ์„ฑํ™”๋Š” ๊ผญ ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋งŒ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋ถˆํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ฐ”๋กœ false๋กœ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ™œ์„ฑํ™” ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝํ•ด์ค๋‹ˆ๋‹ค.

  • Documentation > UIKit > UIApplication > isIdleTimerDisabled
  • ๋””๋ฐ”์ด์Šค ์„ค์ • > ๋””์Šคํ”Œ๋ ˆ์ด ๋ฐ ๋ฐ๊ธฐ > ์ž๋™ ์ž ๊ธˆ > '์•ˆ ํ•จ' ์„ค์ •๋˜์–ด์žˆ์ง€ ์•Š์€์ง€ ํ™•์ธ
  • Xcode์—์„œ Build ํ•œ ๊ฒฝ์šฐ๋Š” ๋””๋ฒ„๊ทธ ๋ชจ๋“œ๋กœ, ์ ˆ์ „๋ชจ๋“œ๊ฐ€ ์ž๋™์œผ๋กœ ๋น„ํ™œ์„ฑํ™” ์ƒํƒœ๋กœ ๋˜๋ฏ€๋กœ, ์•ฑ ์ข…๋ฃŒ ํ›„ ๋‹ค์‹œ ์‹คํ–‰ํ•˜์—ฌ ํ…Œ์ŠคํŠธ ์ง„ํ–‰

Swift

UIApplication.shared.isIdleTimerDisabled = true

Objective-C

[UIApplication sharedApplication].idleTimerDisabled = YES;

 

728x90
๋ฐ˜์‘ํ˜•