Limits on iPhone push notification sounds? - iphone

Does anybody know of any limitations on the sounds that can be played when an iPhone app receives a push notification? Specifically, is there a maximum sound length?
Also, I am assuming that the volume of the sound will match whatever the user has set their ringer volume to, and if set to vibrate mode, the phone will vibrate instead of playing a sound. Is this correct?

I have tested the maximum length of a push notification audio alert, which not surprisingly turned out to be 30 seconds. Any longer audio files will result in the built-in Tri-tone alert being played instead.

I don't know for sure, but based on various API limitations I would guess the length would be 30 sec. max. And yes, the volume of the ringer is the volume of the sound. Same with vibrate mode

You may have to consider "Notification Payload" for that.You can also have Custom Alert Sounds.
See this:Notification Payload

Updated reference to Apple's documentation for 30 seconds.
https://developer.apple.com/library/prerelease/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW10

Here's the reference in Apple's documentation (30 seconds is correct): https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6

Related

Assign alert tone for UILocalNotification from available sounds in iphone

I am working on an app that used UILocalNotification. I wanted to select sound from default sounds that came with iPhone. How can i list down sounds for assign as the alert tone.
There is one standard sound for notification from system (UILocalNotificationDefaultSoundName). You can play any custom sound shorter than 30 seconds. So, if you can download any native sound from ios from anywhere, you will be able to use it as custom sound. Documentation

how to set iPhone vibrate length?

I'm using AudioServicesPlaySystemSound to call vibrate function:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
is there any way to set the duration of the vibrate? i know that the default duration is 0.4 seconds but i want sometimes to make the device vibrate less or more time then this.
You can use these numbers for less vibration.
AudioServicesPlaySystemSound(1519); // Weak
AudioServicesPlaySystemSound(1520); // Strong
You can merge two-three vibration for more vibration duration.
I do not think its possible to alter that vibration duration.. Even if you achieve it using some library but I do not think Apple will be happy about that. There are chances of rejection of your App..
You are not allowed to change the duration of vibration. If you want more you'd have to set it to start vibrating immediately after the first finishes, but Apple has been known to reject for that.

iOS 5 deep sleep prevention

I'm trying to build an alarm app that can fire an alarm while in locked-screen mode (the app is in the foreground, but the screen is locked). The alarm has to be triggered by a NSTimer not by uilocalnotification.
In iOS 4 I used the 'play silent sound every 10 seconds' hack to prevent the app from going to deep sleep and the timer events worked fine. However, in iOS 5 this doesn't seem to work.
Any ideas? Or this should work and I'm doing something wrong?
It seems that you actually can use the 'play silent audio' hack in iOS 5, but the audio has to be audible meaning you can't play it at volume set to 0.0.
You can use github.com/marcop/iPhoneInsomnia and set the volume to greater than 0, but it still doesn't work because the sound file is so short that the system kills your application before the timer is triggered and replays the sound. I solved this by setting the numberOfLoops of the audioPlayer to -1 (infinite repeat). Then it should work.
And you should also set the UIBackgroundMode plist key to an array of one string called "audio"
It's probably a dirty workaround, but in the past I have used the proximity sensor to turn off the screen instead of locking the phone. Simply place the phone upside down and the screen will turn itself off.
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
This will allow you to retain full control over the device, while the screen does turn off.

vibrate in push notification

How can I set that device should vibrate if a push notification come to my application?
I just figured out one way to do this: if you want to phone to only vibrate on receipt of a push notification, you need to have a silent sound file in your application bundle, for example "silence.aif" ... if you specify that sound file in the APS notification, the iOS device will "play" the silence.aif from your application bundle, but since the sound is silence, there is nothing to hear. However the notification vibration is still triggered :-)
I don't think it is possible to instruct the notification to vibrate. If you set a sound using soundName the notification will vibrate if the iPhone has Vibrate set to ON in Settings > Sounds, i.e. it depends on the settings of the individual iPhone.
Setting sound : "default" makes it vibrate for me. Even when phone is not on silent, it plays no sound and only vibrates.
You just need call this line:
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
Omitting the sound key should do the trick:
{"aps":{"alert":{"loc-key":"SOME_KEY"}, "badge":1}
The docs state that "If the sound file doesn’t exist or default is specified as the value, the default alert sound is played.". What they don't say is that if you don't provide a sound key at all, no sound will be played. If no sound is played, the phone should not vibrate as well.
if the iPhone has Vibrate set to ON in Settings > Sounds,and remove "sound="silence.caf",the end will be: doesn't vibrate

iPhone playing sounds while in the background

I have a small application which is much like a clock. It has been working great on IOS3, but now I am updating it to iOS4.
What I want to do in iOS4 is to let it play a sound any giving time. For instance, if I set it to play at 4.00 PM I want it to play a sound, a sound from the application not from the OS. This works if the app is launced, but if the user went back to the home screen I want the same to happen.
It is OK if a UIAlertView pops up istead of the application.
How can I do this?
Best regards,
Paul Peelen
Sounds like you'll need to use a local notification:
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html
and
http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/occ/cl/UILocalNotification
Read http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html.
What you want is UIApplication setKeepAliveTimeout:handler: which let you register a handler that will be called. You can use that to start playing audio. (Of course, compute the timeout when your app goes to background)
EDIT: Use UILocalNotification as andy said.
Two things you could possibly try under iOS 4.
Local Notifications can pop up an alert and play a short sound.
Another power hungry option is to register as a background music player, and play silence until time for the alarm to go off, then add your chosen sound to the "music" output. This will fail if the user switches to another media player app.