问题
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:
And following is that for Skype:
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:
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:
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:
- UIRemoteNotificationTypeBadge
- UIRemoteNotificationTypeSound
- UIRemoteNotificationTypeAlert
- UIRemoteNotificationTypeNone
- UIRemoteNotificationTypeNewsstandContentAvailability
Here's the documentation: Registering for Remote Notifications
Hope that helps!
来源:https://stackoverflow.com/questions/20849566/sound-is-not-played-in-push-notifications