自定义通知声音未播放 iOS objective c
Custom notification sound not playing iOS objective c
我正在尝试让 localNotification
播放自定义声音,但我就是无法让它工作。我已经声明了它并仔细检查了文件类型,但它就是行不通。该文件名为 Alarm Clock.caf
,它已添加到文件中,长度为 29.4 秒,因此符合指南。这是 localNotification
代码:
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.alertBody = @"Hello!";
notification.soundName = @"Alarm-Clock.caf";
notification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification: notification];
如何播放?
谢谢
UILocalNotification *local = [[UILocalNotification alloc] init];
local.timeZone = [NSTimeZone defaultTimeZone];
// set notification details
local.alertBody = @"Alarm!";
local.soundName = [NSString stringWithFormat:@"tring.caf"];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:210]; //time in seconds
这是一个例子。
使用终端从mp4/wav
制作caf文件
afconvert -f caff -d LEI16@44100 -c 1 your.wav your.caf
还要确保 select your.caf
文件并选中目标成员资格
有时即使在限制下,如果时间太长,也会出现故障,导致无法正常工作。尝试缩短它并重命名为不含空格或大写字母的名称,例如 notifsound
。希望这有效!
我正在尝试让 localNotification
播放自定义声音,但我就是无法让它工作。我已经声明了它并仔细检查了文件类型,但它就是行不通。该文件名为 Alarm Clock.caf
,它已添加到文件中,长度为 29.4 秒,因此符合指南。这是 localNotification
代码:
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.alertBody = @"Hello!";
notification.soundName = @"Alarm-Clock.caf";
notification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification: notification];
如何播放?
谢谢
UILocalNotification *local = [[UILocalNotification alloc] init];
local.timeZone = [NSTimeZone defaultTimeZone];
// set notification details
local.alertBody = @"Alarm!";
local.soundName = [NSString stringWithFormat:@"tring.caf"];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:210]; //time in seconds
这是一个例子。
使用终端从mp4/wav
afconvert -f caff -d LEI16@44100 -c 1 your.wav your.caf
还要确保 select your.caf
文件并选中目标成员资格
有时即使在限制下,如果时间太长,也会出现故障,导致无法正常工作。尝试缩短它并重命名为不含空格或大写字母的名称,例如 notifsound
。希望这有效!