0

当用户通过地理围栏进入某个区域时,我会发出本地通知。但是当我按下主页按钮查看本地通知时,它确实会显示但没有声音。我试图在mac设置中禁用和启用“播放用户界面声音..”,关闭并重新打开xcode,清理项目,最后重新启动mac。没有任何效果..我错过了什么?

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Entered Region - %@", region.identifier);
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    [localNotification setAlertBody:@"You are about to enter.."];
    [localNotification setSoundName:@"Voicemail.caf"];

    UIApplication *application = [UIApplication sharedApplication];
    [application presentLocalNotificationNow:localNotification];
}
4

3 回答 3

1

在这里你可以传递你的声音文件名

UILocalNotification *notifThreshold = [[UILocalNotification alloc]init];
    if(notifThreshold)
    {
        notifThreshold.alertBody = statusMsg;
        notifThreshold.alertAction= @"Open";
        notifThreshold.userInfo = userInfo;
        notifThreshold.soundName = UILocalNotificationDefaultSoundName;

        UIApplicationState state = [[UIApplication sharedApplication] applicationState];
        if (state == UIApplicationStateBackground)
        {

        notifThreshold.applicationIconBadgeNumber = [[UIApplication sharedApplication]
                                                     applicationIconBadgeNumber]+1;
        }
        [[UIApplication sharedApplication] presentLocalNotificationNow:notifThreshold];
    }
于 2013-12-03T06:53:05.210 回答
0

请确保您的应用程序在通知中心的声音已启用,而不是使用 cap 扩展尝试使用 wav 扩展,例如“beep.wav”或“Default.wav”......

于 2013-12-03T07:10:05.577 回答
0

转到 Build Phases 并将您的 .caf 文件添加到 Copy Bundle Resources。它帮助了我

于 2013-12-03T06:41:36.680 回答