UILocalNotification does not work ... No vibration on iPhone 4 iOS 4.3

I would write as much as I could write here, but the title pretty much says it all. I tested it in several different situations:

1) The phone is on, silence is turned off, the application is on, in the foreground, the screen is unlocked

I know this happens through the delegate of the didReceiveLocalNotification application and did not expect sound or vibration, except for the processing code that I included in didReceiveLocalNotification. Processing 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 it really works! It reproduces sound and vibrates the phone at the same time.

2) the phone is on, silence is turned off, the application is on, in the background, the screen is unlocked

Now I have configured my uilocalnotification avatars in the application delegation application 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 it only partially works! The sound is playing, but there is NO VIBRATION! Now, I think this is a mistake, because I am quoting from the Apple developer website

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html , "Planning the delivery of local notifications":

"When a notification is sent and sound is played, the system also vibrates on devices that support it."

Now, obviously, this IS NOT a MATTER for my iPhone, and obviously the simulator does not vibrate, so I can’t check it and would like it to be considered in the developer community!

3) the phone is on, silence is turned off, the application is on, in the foreground, locked on the screen

Same as # 2

4) the phone is on, silence is turned off, the application is on, in the background, locked on the screen

Same as # 2

5) the phone is turned on, silence is turned off, the application is turned off (the background process is deleted)

Same as # 2 because uilocalnotifications have never been canceled, so iOS still thinks they are valid.

6) the phone is on, the mute mode is on, the application is on, in the background, the screen is unlocked

no sound, vibration, NOTHING! This sucks! I would hope that the apple comes up with something that works right out of the box, as usual!

+4
source share
3 answers

These are the parameters and effects (all suggest that the volume is set to some reasonable value):

Option 1:

Configuration:

  • [Developer controlled] Actual sound name set to UILocalNotification = No
  • [Custom] Application Notification Center: Sound = N / A
  • [User Mode] Quiet Mode (iPhone side switch) = N / A

Behavior:

  • Sound played with notification = No
  • Vibrate with notification = No

Option 2:

Configuration:

  • A valid beep name set to UILocalNotification = Yes
  • Setting the notification center for the application: Sound = Off
  • Quiet mode (iPhone side switch) = N / A

Behavior:

  • Sound played with notification = No
  • Vibrate with notification = No

Option 3:

Configuration:

  • A valid beep name set to UILocalNotification = Yes
  • Setting the notification center for the application: Sound = On
  • Quiet mode (iPhone side switch) = None (not selected)

Behavior:

  • Sound played with notification = Yes
  • Vibrate with notification = No

Option 4:

Configuration:

  • A valid beep name set to UILocalNotification = Yes
  • Setting the notification center for the application: Sound = On
  • Quiet mode (power on iPhone side) = Yes (selected)

Behavior:

  • Sound played with notification = No
  • Vibrate with notification = Yes
+3
source

The following work with sound and 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 may sound a little silly, but have you possibly turned off the vibration in your iPhone settings?

+2
source

Sorry to report this as an answer, but my comment is too long to post under your name. So I just posted a fragment there, and the rest here. It was the answer to Tony’s millionth answer.

Hi Tony, Thanks for your input, however I'm not sure which of the things you changed had an effect. If I noticed correctly, you have changed the following items:

1) scheduleLocalNotification → presentLocalNotificationNow

2) by explicitly setting the UILN repeatInterval

3) by explicitly setting the UILN alertBody

4) by explicitly setting the UILN alertAction

Apart from these four changes, I see nothing more. Which of these causal changes do you consider appropriate for you.

Lol ... it wasn’t necessary to feel that this is a silly question. Although, I mentioned in my post "Turn on / off silent mode", I did not indicate what this means. I spoke especially about the switch on the side of the phone. I didn’t even have to check the iPhone settings! Haha So that was a good question! Unfortunately, however, it was not disconnected, and it successfully vibrated when in scenario # 1 from OrigPost.

+1
source

Source: https://habr.com/ru/post/1345358/


All Articles