使用iOS7的iPhone 4S无法播放本地通知声音

时间:2014-06-10 11:57:00

标签: ios iphone objective-c

我的应用程序存在一个问题,当收到警报本地通知时,声音无法在 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];

2 个答案:

答案 0 :(得分:0)

我想你忘了在你的代码中添加这一行

     [localNotification setSoundName:UILocalNotificationDefaultSoundName]

答案 1 :(得分:0)

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

通知声音不会有所不同,具体取决于设备或操作系统版本。问题在于设备设置。

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

enter image description here