打开通知声音不起作用但通知即将到来

时间:2014-11-25 07:01:54

标签: objective-c uilocalnotification

我正在尝试使用客观c代码中的声音进行本地通知,但我无法获得声音。我的通知即将发布,但听起来不起作用。

UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;

localNotif.timeZone = [NSTimeZone defaultTimeZone];

localNotif.alertBody=msg;
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
//localNotif.soundName=@"sound.caf";
localNotif.applicationIconBadgeNumber = 1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

1 个答案:

答案 0 :(得分:0)

通常会出现此问题,因为声音文件可能无法添加到目标捆绑资源。

Select project file--> Target--> Build phases--> Copy bundle resources

然后添加声音文件(如果未列出)。 声音文件应采用允许的格式(.caf,.aiff等..)