我可以发送没有声音的本地通知吗?

我想有几个本地的通知没有显示,没有声音,但只有一个振动。 我可以通过设置alertBody@""来让它不做任何显示,但是我怎样才能发出声音呢? 我在想,如果我没有从你们那里得到更好的办法,那么我将能够发出一个空的声音,将它添加到我的项目中,然后将soundName设置为该声音。 但有没有什么默认的方式来做到这一点?

如果我添加一个虚假的声音名称,它仍然播放默认的通知声音。

谢谢!!

不,您不能禁用声音,因为UILocalNotification不提供任何选项。 所以更好的select是你在你的问题中使用一个空的声音文件。

是的,你可以添加另一个声音文件。

 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]; 

在上面的代码中,只需将您保存在资源中的声音文件的名称replace为“soundFile”string即可。

你不能设置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); 

}