testing on actual device problem

Hi everyone , Im going to release my first application but before that , I found a big problem on my device testing,

my problem was that "application stops timer(stops to work) after lock screen on actual device but work perfectly on simulator."

is that because I haven't released so actual device won't let me keep working on lock screen? or it's a bug in my code?


I've write an NSLog to monitoring my application timer action, it keeps working when simulator goes to sleep(lock screen)

but on actual device......it stops.


Im so frustrating because I don't know why there has some diffences between actual device and simulator and don't know how to slove it.


hope someone can help me solve this problem.

>I don't know why there has some diffences between actual device and simulator


That's becuase the simulator isn't an emulator - it runs code for your computer/OS X.


>application timer action


Show that code here, along with any errors. Also describe the device testing environment, etc.

Im writting a clock app and use avaudioplayer to play clock music, I've set the code below to prevent avauio goes to sleep

AVAudioSession *audioSession = [AVAudioSession sharedInstance] ;

[audioSession setCategory : AVAudioSessionCategoryPlayback error : nil] ;

[audioSession setCategory: AVAudioSessionCategoryPlayback error: nil];

[audioSession setActive : YES error : nil] ;


and use a timer to play audio when the current time and dest time match

sleepTimer = [NSTimer scheduledTimerWithTimeInterval : 1 target : self selector : @selector(fireClock) userInfo : nil repeats : YES] ;

in fireClock method I wrote NSLog to print something for checking if it still work when device is locking

and it works perfectly in simulator, nslog keeps printing while locking and avaudio plays while device sleeping,

but on actual device testing , nslog stops printing(it means my app stops i think) and avaudio doesn't play.

I solve it ! I've added “Required background modes” - App plays audio or streams audio/video using Airplay into my Info.plist

and my app can keep playing avaudioplayer while locking screen.


Thanks for replying my question.

testing on actual device problem
 
 
Q