Can I send a local notification without sound?

I want to have several local notifications without display and without sound, but only with vibration. I can make it not display by just setting alertBody to @"" , but how can I send a sound? I think if I don’t get the best from you guys, I can just make the sound empty, add it to my project, and then set the soundName for that sound. But is there a default way to do this?

If I add a fake sound name, it still plays the default notification sound.

Thanks!!

+4
source share
3 answers

No, you cannot turn off the sound because UILocalNotification does not provide any parameters for this. Thus, the best option, as you said in your question, is to use an empty sound file.

+3
source

Yes, you can add another sound file.

 NSString * soundFile=@ "temp.mp3"; UILocalNotification* localNotification = [[UILocalNotification alloc] init]; if (localNotification==nil) { return; } localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60]; localNotification.alertBody = @"Your alert message"; localNotification.soundName = soundFile; localNotification.timeZone = [NSTimeZone defaultTimeZone]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

In the above code, simply enter the name of the sound file that you saved in your resources instead of the string "soundFile".

+3
source

You can not install sound.or

 -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)responsewithCompletionHandler:(void (^)())completionHandler{ NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNCalendarNotificationTrigger class]]) {} else{} //don't write UNNotificationPresentationOptionSound completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); 

}

0
source

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


All Articles