UILocalNotification自定义声音不在iOS7中播放

Jay*_*tra 16 iphone audio ios uilocalnotification ios7

我正在UILocalNotification申请中使用.

在应用程序中有两种声音有条件地播放 - 我已经为它们应用了适当的条件.

但是当我安装应用程序并在iOS 7设备上运行它时,它会触发本地通知,但声音不会在应用程序中播放.

下面给出了代码来设置通知:

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    if (localNotification == nil)
        return;
    localNotification.fireDate = [pickerView date];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];

    if (alarm_number == 1) {
        localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"];
    }
    else
    {
        localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"];
    }

    localNotification.alertAction =@"Ok";

    NSString *message = [[NSString alloc]initWithString:@""];

    if(alarm_number == 1)
    {
        localNotification.soundName=@"Alarm_1.mp3";
        message = @"First Alarm Scheduled";
    }
    else
    {
        localNotification.soundName=@"Alarm_2.mp3";
        message = @"Second Alarm Scheduled";
    }

    localNotification.applicationIconBadgeNumber = 1;

    // Specify custom data for the notification
    NSString *alarmString;
    if (alarm_number==1) {
        alarmString = [NSString stringWithFormat:@"First Alarm"];
    }
    else
    {
        alarmString = [NSString stringWithFormat:@"Second Alarm"];
    }

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmString forKey:@"AlarmFor"];

    localNotification.userInfo = infoDict;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
Run Code Online (Sandbox Code Playgroud)

我检查过的是我的应用程序的设置/通知中心应用程序中的声音设置.

请查看第1张到第3张图片以查看我查看过的内容.

(1)通知中心

(1)通知中心

(2)申请

在此输入图像描述

(3)声音在这里关闭

在此输入图像描述

因此,为了启用此功能,我已在应用程序的目标功能中检查了Inter App Audio,它已关闭,如下图所示.

应用间音频的功能

应用间音频的功能

然后我将其更改为On,它看起来如下图所示.

更改后的功能

然而,它仍然没有在iOS 7设备中播放任何声音.

有没有人知道它为什么不起作用?这将是一个很大的帮助.

谢谢.

小智 9

您是否尝试关闭"请勿打扰"模式?我有同样的问题,然后我发现"请勿打扰".关闭后,一切正常.


Jay*_*tra 0

我不知道为什么它有效。

但是,最后我通过在 Xcode 5.0 中创建一个新项目并将旧项目移植到这个新项目中解决了我的问题。所以它工作正常,我也能听到声音。