Sound is not played in push notifications

喜夏-厌秋 提交于 2021-02-07 22:47:04

问题


I am using iOS 7 and my push notifications do not play sounds.

Strangely, I found there is no setting for sound in the Preference > Notification Center for my app. Following is the screenshots of Notification center for my app: enter image description here

And following is that for Skype:

enter image description here

You see, there is no 'Sounds' section for my app.

Could anyone help?


Update:

Now I have registered sound in my app. The Notification Center now looks like: enter image description here

and my notification has sounds. Looks good.

But after I enter the setting of my app, there is initially a 'Sounds' section like Skype, but then the Preference app crashed, and after that, there is no more 'Sounds', just like below: enter image description here

Might it be a bug of Apple?


回答1:


You're not registered for audio push notifications in your app. Just register for it like this in your App Delegate:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Whatever you have already in your app delegate...

    // Let device know you're going to be sending one of these types of notifications.
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    return YES;
}

The 5 types are:

  1. UIRemoteNotificationTypeBadge
  2. UIRemoteNotificationTypeSound
  3. UIRemoteNotificationTypeAlert
  4. UIRemoteNotificationTypeNone
  5. UIRemoteNotificationTypeNewsstandContentAvailability

Here's the documentation: Registering for Remote Notifications

Hope that helps!



来源:https://stackoverflow.com/questions/20849566/sound-is-not-played-in-push-notifications

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!