iPhone - phone goes to sleep even if idleTimerDisabled is YES

前端 未结 9 1375
难免孤独
难免孤独 2020-11-30 03:45

I am using this in my appdelegate\'s applicationDidFinishLaunching: method to make sure the iPhone doesn\'t go to sleep during the time the app is open

[appl         


        
9条回答
  •  遥遥无期
    2020-11-30 04:12

    i had the same problem. i need to make the screen dim, but when turn off the camera, the iphone goes to sleep.

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    }
    

    Then i call it after turn on/off the camera, it works.

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    

提交回复
热议问题