Charles D'Monte
Charles D'Monte

Reputation: 372

Perform a function at a particular time

I am trying to do an app which make a song sing at a time set by the user. The user should set the time by opening the app. Even after the user force kills the app after setting the time, I must be able to make the song sing at the particular time. How do I do this?

Upvotes: 0

Views: 71

Answers (2)

CRDave
CRDave

Reputation: 9285

You can do this but not without user interaction if your app is not running.

Set Local Notification for time which user set.

At that time your app will be notified by two way
1 If your app is running : didReceiveLocalNotification:(UILocalNotification *)notification
2 If your app in not running : didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

And you can play song from here.

To learn you can visit this :

  1. iPhone Programming Tutorial – Local Notifications
  2. iOS Multitasking: Local Notifications

Upvotes: 1

lukaswelte
lukaswelte

Reputation: 3001

To be able to play the song also when force quitting you need to do this by push notifications.

You can add the small sound to the Push Notification. So you need to store the sound snippet and the time on the server and trigger a push notification with the sound attached on the server. Or using LocalNotifications.

This will do the trick for you. Otherwise you can just play the sound if the app is running.

Upvotes: 0

Related Questions