2012-04-27 249 views
2

我在执行该通知是这样的:IOS推送通知声音不工作

-(void)scheduleLocalNotificationWithDate:(NSDate *)AlarmDate{ 
    UILocalNotification *Notification = [[UILocalNotification alloc]init]; 
    Notification.fireDate = AlarmDate; 
    Notification.alertBody = @"Time to wake up!"; 
    Notification.soundName = @"sound.caf"; 
    [[UIApplication sharedApplication] scheduleLocalNotification:Notification]; 
} 

所以,当火灾通知有没有声音。可能是什么问题?

*文件名是正确的 *声持续时间:分32秒 *我使用的IOS模拟器 *声音是在“支持文件”,“物理”也试过项目文件夹 *设定绝对路径,但该也没有帮助。

UPD:不是本地的,推送通知(我的意思是,即使你关闭应用程序,将工作)

回答

0

我很困惑,你说你发送推送通知,但你的代码显示本地通知。

对于一个推送通知,您的应用可以指定它想要的声音时,它得到了推送通知令牌:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound)]; 

如果您最初注册的通知,而无需请求音频通知的应用程序,你可能需要删除你的应用程序,并在iOS之前重新安装,你的应用程序已经改变了主意。

另外,请确保在设置>通知> YOUR_APP中打开声音。

另外,Apple的Local and Push Notification Programming Guide表示自定义声音的长度最多可能是30秒,否则会播放默认通知。这适用于推送和本地通知。

1

本地通知不会在iPhone模拟器很好地工作,你应该试着他们在真实设备上。

0

本地通知在模拟器上处理声音(我刚刚使用Xcode 7.1进行了测试),但如果剪辑长度超过30秒,声音将无法播放。