简体   繁体   English

在装有iOS7的iPhone 4S中无法播放本地通知声音

[英]Local notification sound not playing in iPhone 4S with iOS7

I have one issue with my app, When receive alert local notification the sound not playing in iPhone 4s (iOS 7)(phone is locked) but work in iPod(ios 6.1.6) and iPhone 5(iOS 8) . 我的应用程序有一个问题,当接收警报本地通知时,声音无法在iPhone 4s(iOS 7)(手机已锁定)播放,但可以在iPod(ios 6.1.6)iPhone 5(iOS 8)播放 i use the following code.. 我使用以下代码。

// 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];

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

     [localNotification setSoundName:UILocalNotificationDefaultSoundName]

If your notification works well in other iOS devices, then it should also works in 4S. 如果您的通知可以在其他iOS设备上正常运行,那么它也可以在4S中运行。

Notification sound will not differ depends on the device or OS version. 通知声音不会有所不同,具体取决于设备或操作系统版本。 So problem lies in the device settings. 因此问题出在设备设置上。

Make sure you enabled the notification sounds in the device settings 确保在设备设置中启用了通知声音

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM