2014-11-25 82 views
0

我试图用声音在本地通知目标c代码,但我无法获得声音。我的通知即将到来,但声音无效。打开通知声音不工作,但通知即将到来

UIUserNotificationType types = UIUserNotificationTypeBadge | 
UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 

UIUserNotificationSettings *mySettings = 
[UIUserNotificationSettings settingsForTypes:types categories:nil]; 

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 
UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
if (localNotif == nil) 
    return; 

localNotif.timeZone = [NSTimeZone defaultTimeZone]; 

localNotif.alertBody=msg; 
localNotif.alertAction = NSLocalizedString(@"View Details", nil); 
localNotif.soundName = UILocalNotificationDefaultSoundName; 
//[email protected]"sound.caf"; 
localNotif.applicationIconBadgeNumber = 1; 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
+0

是你的iPhone在静音模式:P – 2014-11-25 07:40:44

+0

没有我的iPhone不处于静音模式。 – 2014-11-25 09:03:22

+0

然后进入设置并检查声音是否打开,以便推送您的应用程序... – 2014-11-25 13:07:49

回答

0

一般会出现此问题,因为声音文件可能无法添加到目标捆绑软件资源。

Select project file--> Target--> Build phases--> Copy bundle resources 

然后添加你的声音文件,如果它没有列出。 声音文件应该是允许的格式(.caf,.aiff等..)