I would write as much as I could write here, but the Title pretty much says it all. I've tested it in several different situations:
I know that this goes through app delegate's didReceiveLocalNotification and didn't expect a sound or vibration, except for the handling code that I included under didReceiveLocalNotification. The handling code actually called
NSURL *Sound = [[NSBundle mainBundle] URLForResource: self.currentSoundPVC
withExtension: @"caf"];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);
AudioServicesPlayAlertSound (soundFileObject);
and that actually works! It plays a sound and vibrates the phone simultaneously.
Now, I set up my uilocalnotification alarms in app delegate's applicationDidEnterBackground, using the following code
NSString *Sound = [self.currentSoundPVC stringByAppendingString:@".caf"];
UILocalNotification* alarm = [[[UILocalNotification alloc] init] autorelease];
alarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
[alarm setSoundName:Sound];
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
and this only partially works! The sound gets played but there is NO VIBRATION! Now, this I think is a bug because I am quoting from the apple developer website,
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html , Scheduling the Delivery of Local Notifications section:
"When the notification is sent and the sound is played, the system also triggers a vibration on devices that support it. "
Now, obviously that is NOT THE CASE for my iPhone and obviously the simulator doesn't vibrate, so I can't test this and would like to have this addressed in the developer community!
Same as #2
Same as #2
Same as #2, because the uilocalnotifications were never cancelled, so the iOS still thinks they are valid.
no sound, no vibration, NOTHING! This sucks! I would have hoped that apple would have come up with something that works straight out of the box, as usual!
These are the options and the effects (all assume the volume is set to some reasonable value):
Configuration:
Behaviour:
Configuration:
Behaviour:
Configuration:
Behaviour:
Configuration:
Behaviour:
the following works with a sound and a vibration:
// Create a new notification
UILocalNotification * notif = [[[UILocalNotification alloc] init] autorelease];
if (notif)
{
notif.repeatInterval = 0;
notif.alertBody = @"NOTIFICATION!!"];
notif.soundName = @"sound.caf";
notif.alertAction = NSLocalizedString(@"View", @"View");
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
}
I know this might sound a bit silly, but have you perhaps turned off vibration in your iPhone settings?
Sorry for posting this as an answer but my comment was too long to post under yours. So I just put a snippet there and the rest here. This was a reply to tony million's answer.
Hi Tony, Thanks for your input, however I am not sure which of the things that you changed had an effect. If I am noting correctly you changed the following items:
1) scheduleLocalNotification --> presentLocalNotificationNow
2) explicitly setting UILN repeatInterval
3) explicitly setting UILN alertBody
4) explicitly setting UILN alertAction
Other than those four changes, I don't see anything else. Which of these causal changes would you think had the desired effect for you.
Lol...no need to feel like that was a silly question. Although, I did mention in my post, "silent mode on/off", I did not specify what that meant. I was talking particularly about the switch on the side of the phone. It didn't even occur to me to check the iPhone settings! Haha! So, it was a good question! Unfortunately, however, it wasn't turned off and it had successfully vibrated when in scenario #1 from OrigPost.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.