简体   繁体   中英

Call method from background

I want do code an alarm-clock. Now the alar-clock should play a music-file at a specific time. But I don't know how to call the method with AVAudioPlayer while the app is in background? Can you please help me I want do this for the first time.

thanks :)

You should not use a long-running background thread in order to trigger a sound at a certain time. A running thread prevents the device from going to sleep, greatly increasing power requirements.

Further, Apple greatly restricts the amount of processing you are allowed to do from the background. You can request time to complete a long task from the background, but only a short period of time is allowed. (A few minutes at most if memory serves.

You should probably create a local notification instead. The local notification will display a banner message on the lock screen if your app is not running, and optionally play a sound that you specify.

Take a look at the UILocalNotification Class Reference in Xcode for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM