vibrate in push notification - iphone

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

Related

Playing loop sound at certain time when iphone app is in background

I have a Clock Alarm app that plays sound at certain time (Sending local notifications). Is it possible to play loop sound at certain time (when local notification comes) when app is placed in background ?
Just want to specify: I need to play loop sound, not only once
No. The reason why is because you won't be able to execute any code because of a local notification. One thing you can do, and it's totally up to you if this is something your app really needs to di, it to list this application as an audio application on the UIBackgroundModes key of your .plist file, and just change song that is playing at the time it has to. You can use a dispatch_after block to change the song at the time you want it to.
Make your app a long running background app as described in this link here

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

Not getting sounds for Notifications or Messages in my Audio app when music is playing | AVAudioPlayer

I have an Audio app using AVAudioPlayer on iOS. Whenever music is playing my app and a new notification or a message comes, my player continues playing and there is no notification sound for the message.
I want that it should work in similar way default music app in iOS works, whenever a new message or notification comes music sound ducks for a while and notification sound is played and after that music starts playing normally again.
I read that setting kAudioSessionProperty_OverrideCategoryMixWithOthers to true should fix it as it allows mixing of sounds. I tried that as well, but it doesn't work and this also allows my app to play music along with other apps which I don't want.
All I want is whenever a message or notification comes when my app is playing music, I should get a notification sound and my app then continues playing.
Any help would be appreciated!
Finally after a lot of try I figured it out, I had set AVAudioSessionCategoryPlayAndRecord property which was causing the above error I mentioned. removing that fixed the issue

UILocalNotification custom soundName only vibrates phone when alertBody is specified (unlike UILocalNotificationDefaultSoundName)?

I have a VoIP app that uses a UILocalNotification to notify the user of an incoming call when the app is in the background. When a notification is presented I would like it to play a sound & vibrate the phone -- more than once (and without presenting the same message repeatedly). I was able to do this by using a series of notifications - the first would immediately present the message and play a sound (the phone would vibrate as well) - following notifications were scheduled 3 seconds apart; they do not have an alertBody and alertAction but do have the same soundname as used in the first notification. HERE IS MY PROBLEM.. if a soundName other than the UILocalNotificationDefaultSoundName is specified the phone will only vibrate for the first notification (the sound will be played each time though). However, if the default soundName is used, then the phone will vibrate with each notification? Is there another way to do this?
Found another way.. display local notification and then start repeating the vibration via a timer.
Interesting. Sounds like a bug. File it with Apple and you might be able to get them to take care of it.

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.