【问题标题】:Local notification sound not playing in iPhone 4S with iOS7本地通知声音在 iOS7 的 iPhone 4S 中不播放
【发布时间】:2014-06-10 11:57:00
【问题描述】:

我的应用程序有一个问题,当收到警报本地通知时,声音没有在 iPhone 4s (iOS 7)(手机已锁定) 中播放,但在 iPod(ios 6.1. 6)iPhone 5(iOS 8)。我使用以下代码..

// Schedule the notification

UILocalNotification* localNotification = [[UILocalNotification alloc]init];
localNotification.fireDate = itemDate;
NSLog(@"%@",index);
if (appDelegate().check == 0) {
    [self repetationType:index Notification:localNotification];
}

//setting repetation type
//UILocalNotificationDefaultSoundName

localNotification.soundName=@"Message Alert - Happy.wav";
NSString *str=[NSString stringWithString:NSLocalizedString(@"youhave", nil)];

localNotification.alertBody=[NSString stringWithFormat:@"%@ %@",str,reminName];//remindtext;
NSLog(@"%@",localNotification.alertBody);
localNotification.alertAction = NSLocalizedString(@"item", nil);
localNotification.timeZone = [NSTimeZone defaultTimeZone];
// localNotification.applicationIconBadgeNumber=[[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
localNotification.applicationIconBadgeNumber=1;

NSString *alarm=[[NSString alloc]initWithFormat:@"%@",reminName];
// NSDictionary *userDict=[NSDictionary dictionaryWithObjectsAndKeys:image,@"info",nil];
NSDictionary *userDict = [NSDictionary dictionaryWithObject:alarm forKey:@"info"];
NSLog(@"userDict=%@",userDict);
localNotification.userInfo=userDict;

[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

【问题讨论】:

    标签: ios iphone objective-c


    【解决方案1】:

    我认为您忘记在代码中添加这一行

         [localNotification setSoundName:UILocalNotificationDefaultSoundName]
    

    【讨论】:

    • keyur 我添加了自定义声音..like localNotification.soundName=@"Message Alert - Happy.wav";
    • @user3725874 确保声音实际上在您的应用程序包中,格式正确(线性 PCM 或 IMA4 — 几乎任何解释如何为 iOS 转换声音的地方都会告诉您如何做到这一点),不到 30 秒。
    • 是的,我将文件添加到应用程序包中,它可以在 ipod 和 iphone 5 中播放,但不能在 iphone 4s 中播放
    • 我希望声音按钮和音量打开...:)
    • 我检查一下。声音按钮和音量打开
    【解决方案2】:

    如果您的通知在其他 iOS 设备上运行良好,那么它应该也适用于 4S。

    通知声音不会因设备或操作系统版本而异。所以问题出在设备设置上。

    确保您在设备设置中启用通知声音

    【讨论】:

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