How to play music when receive local notification on background - ios

I'm making an alarm function for my app and local notification is one of method I have searched. But when receive local notification it enable only 30s for it sound while I want my alarm play sound on 15 minute.
I can make 1 alarm sound on 15 minute with 30 notifications but my app need create a lot of alarm while iOS app allow only 64 or 128 local notifications. So I would like to run music on background when receive the notification, but how to do this?
Can anybody help me with this?
Many thanks.

If you want your app to play a 15 minute sound then you are going to need to set it up with the background mode flags in info.plist that declare it as a background sound playing app. You'll then need to ask for background time and quit background mode once your sound is complete.

Related

Push Notification sound stops when the notification badge disappears

I need to play notification sound for a long time (20-25 sec) when the app is in background. I have imported my custom sound file (25 sec in duration) in the project. Custom sound is playing but the problem is it only plays as long as the notification badge remains on the screen, i.e. 3-4 sec. As soon as the badge disappears, the notification sound also stops. What should I do ?
In this link Managing Your App’s Notification Support, go to section title Preparing Custom Alert Sounds
It mentions, Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
Possible duplicate of Limits on iPhone push notification sounds?

Play sound at a specific time in background iOS

I have a muslim app that triggers local notifications with sounds for prayer times throughout the day. The sounds are limited to 30 seconds. I am searching for a workaround to play sound longer than that.
I found out I can use AVAudioSession to play audio even if the app is in background by turning on Background Modes (Audio, Airplay, and Picture in Picture) in Capabilities target tab and using background task to play the audio. However I want to play sound at a specific time by scheduling it.
Among the workarounds I found are also setting continuous local notifications. However I came across an alarm app (Alarmy) that can play sound when local notification is received. How is that doable? Thank you in advance!

Is it possible for timer running in iOS background?

I made a timer. After I hit home button in iOs simulator, it was still running in the background. I didn't save the state, I only added local notification. Why is that?
Also, I set to play a 4 seconds sound in notification and it came out that the sound only played 3 seconds. Is there a limitation of how long the sound can play for notification?
Maybe you selected one of them:

UILocalNotification - play sound longer than 30 seconds

I am trying to develop an alarm app for iOS.
I have implemented it using UILocalNotification, but the issue is that local notification will allow playing local audio for 30 seconds. So I am looking for some way to extend this playing time.
Is there any way to play online MP3 or media file while the app is in background and when the notification occur by enabling background mode to play music?
There is no way to achieve this. Playing silent sound to keep the app running in background is against Apple rules and your app will be rejected (I know this by experience). Furthermore, playing audio in background eats the battery quickly.
You can try to schedule multiple notifications, but it is not a clean solution either.

How to detect if UILocalnotification sound is playing or not

In my application I am using 'UILocalNotification` with a 30 sec audio file. I fire the notification when device is in lock mode. I tried to drag the notification on lock screen, then application will open at that Notification sound is playing, I need to recognize notification sound is playing or not when app is in foreground.
No good way, but you can use NSTimer. Start timer after show notification and make work when timer notify you. It will work, but use it only if any other resolution don't work.

Resources