2013-01-18 27 views
0

欲用戶通知某些事件被觸發,這樣我使用亮度 [UIScreen mainScreen] .brightness = 1.0 // 0.0替代地
它是工作正常,當應用在前臺模式,但 當應用程序是後臺模式,並在那個時候觸發該事件我的代碼不起作用。 我使用了位置,所以我的應用程序能夠在後臺運行。變化的ios5裝置亮度時在後臺模式應用

給我建議當應用程序處於後臺模式時如何設置亮度。

回答

0
- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 

    // UIBackgroundTaskIdentifier *bgTask = nil; 
    UIApplication *app = [UIApplication sharedApplication]; 


    counterTask = [[UIApplication sharedApplication] 
        beginBackgroundTaskWithExpirationHandler:^{ 
         [app endBackgroundTask:counterTask]; 
         counterTask = UIBackgroundTaskInvalid; 

         // If you're worried about exceeding 10 minutes, handle it here 
         theTimer=[NSTimer scheduledTimerWithTimeInterval:20 
                   target:self 
                   selector:@selector(YourFunction) 
                   userInfo:nil 
                   repeats:YES]; 
        }]; 

    count=0; 
    theTimer=[NSTimer scheduledTimerWithTimeInterval:20 
               target:self 
              selector:@selector(YourFunction) 
              userInfo:nil 
              repeats:YES]; 

    //[super viewDidLoad]; 

}