【问题标题】:Sound file not playing on Local notification iOS7声音文件未在本地通知 iOS7 上播放
【发布时间】:2014-02-26 03:03:32
【问题描述】:

我正在 iPod Touch (iOS 7) 上运行本地通知应用程序。通知即将到来,但通知的声音未播放。我已将声音文件放在文件夹中,并检查了设备上的声音设置。我尝试了许多声音文件,但没有任何效果。下面是代码:-

- (IBAction) scheduleAlarm:(id) sender {
    [eventText resignFirstResponder];

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

    // Get the current date
    NSDate *pickerDate = [self.datePicker date];

    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) 
                                                   fromDate:pickerDate];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) 
                                                   fromDate:pickerDate];

    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
    // Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
    [dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    // Notification details
    localNotif.alertBody = [eventText text];
    // Set the action button
    localNotif.alertAction = @"View";

    localNotif.soundName = @"alarm.wav"; ///UILocalNotificationDefaultSoundName;

    //    notify.soundName = @"../Documents/blabla.caf"

    localNotif.applicationIconBadgeNumber = 1;
    localNotif.alertBody = @"Staff meeting in 30 minutes";

    // Specify custom data for the notification
    //  NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    // localNotif.userInfo = infoDict;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

    [self.tableview reloadData];
}

【问题讨论】:

    标签: ios ios7 ipod localnotification


    【解决方案1】:

    有时这可能是由于设备的原因。并尝试清除之前的通知:

    UIApplication* app = [UIApplication sharedApplication];
    [app cancelAllLocalNotifications];
    

    检查此answer。这可能会帮助您解决问题。

    【讨论】:

    • 谢谢,我试试看。
    • 你知道我们是否可以在iOS7的文档文件夹中播放通知声音吗?
    • 据我所知,这是不可能的。 :)
    • 在这个链接中有人提到了下面的方式,但对我不起作用。 stackoverflow.com/a/9986482notify.soundName = @"../Documents/blabla.caf"
    【解决方案2】:

    请先尝试设置->通知中心->声音是否没有关闭。然后检查设置->声音->滑块是否不为零。这意味着如果你的声音为零,则不允许声音出现. 希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多