4

I have been trying to get my device to vibrate more than once when my app is in the BACKGROUND. I do get one vibration only using the UILocalNotification presentLocalNotification api. All the questions I have read on stackoverflow related to this on stackoverflow says that it can't be vibrated more than once (and its against Apple policies if done so).

But in this video http://www.youtube.com/watch?v=AHtDMqOJeNk#t=38 the jabber app does it quiet nicely. Any idea how it is done ?

[Update] - all the answers below are for apps to vibrate more than once when in the foreground. I need it to vibrate in the background.

FatalError
  • 574
  • 1
  • 7
  • 18

1 Answers1

1

Apple's documentation for UILocalNotification doesn't seem to provide any way to specify the vibration of the notification. However, you can set a custom sound or a system sound using the soundName parameter. I would imagine that some system sounds, by default, vibrate more than once.

You may also be able to subscribe to notification events in your AppDelegate and play another vibration sound there:

#import <AudioToolbox/AudioServices.h>
...
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

If your app is running, the following method is called in the AppDelegate:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif

It may also be worth it to take a look at this GitHub project for a list of system sounds (no guarantees as to whether or not this is AppStore-safe).


A note on AppStore review with this kind of feature implemented. I checked the guidelines for iOS apps, and there is nothing in there about notification sounds, vibrations, or alert types. However, the use of private APIs is immediate grounds for rejection. So if you can do this without using private APIs then chances are your app will be approved.

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
  • didReceiveLocalNotification - is only when you take action on the local notiifcation (out of the app notification) AudioServicesPlaySystemSound - works only when you are in the foreground. doesnt help when you are in the background. – FatalError Mar 05 '14 at 22:02
  • I realized that and noted it in my answer. It may be possible to specify a system sound with more than one vibration for a UILocalNotification - although I'm not 100% sure. – Sam Spencer Mar 06 '14 at 03:00
  • @Sam, hello, could you please explain what do you mean by: "system sound with more than one vibration for a UILocalNotification", can i make a custom sound that will provide more than one vibration or do you have an example by any chance??? thanks – Guy S Jun 25 '14 at 07:26
  • @GuyS I meant that Apple's own system apps (e.g. phone calls, messages, mail, calendar, etc.) can have more than one vibration or custom vibrations for their notifications. However, third-party apps (last time I checked) do not have this freedom. – Sam Spencer Jun 25 '14 at 19:38
  • @GuyS - my understanding as well. I do have hope to find out what APIs that app in the youtube video is using :) ! – FatalError Aug 26 '14 at 00:46