简体   繁体   中英

IOS push Notification sound doesn't work

I am implementing the notification this way:

-(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];
}

So, when the notification fires there's no sound. What may be the problem?

*file name is correct *sound duration: 32sec *I am using IOS simulator *sound is in "supporting files", "physically" also in the project folder *Tried to set the absolute path but that didn't help either.

UPD: not local, Push notification.(i mean even if you close the app it will work)

在iPhone模拟器上,本地通知无法正常运行,您应该在真实设备上尝试使用。

I'm confused, you say you're sending a push notification but your code shows a local notification.

For a push notification, your app has to specify that it wants sounds when it gets its push notification token:

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

If your app initially registered for notifications without requesting audio notifications, you may have to delete your app and reinstall before iOS notices that your app has changed its mind.

Also, make sure that Sounds is turned on in Settings > Notifications > YOUR_APP.

In addition, Apple's Local and Push Notification Programming Guide says that custom sounds may be at most 30 seconds in length, otherwise the default notification is played. This applies to both push and local notifications.

本地通知会在模拟器上带有声音(我刚刚使用Xcode 7.1进行了测试),但是如果剪辑超过30秒,声音将不会播放。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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