简体   繁体   English

推送通知不振动且保持沉默

[英]Push notifications don't vibrate and are silent

I have created push notifications using Parse which are successfully sent to my device (real-world, not a simulator). 我使用Parse创建了推送通知,这些通知已成功发送到我的设备(真实世界,而不是模拟器)。 However, these push notifications appear silently, not vibrating my phone, nor making any sound to notify the user. 但是,这些推送通知会静默显示,不会振动我的手机,也不会发出任何声音来通知用户。 This is the case if the phone is locked, and when the phone is on, but not running the app. 如果手机处于锁定状态,并且手机处于开机状态但未运行应用程序,则属于这种情况。

I have code in the didReceiveRemoteNotification: method to play a sound, which is played when the app is running. 我在didReceiveRemoteNotification:方法中有代码来播放声音,该声音在应用程序运行时播放。 However, how can I play a sound, and get my phone to vibrate, when the device receives a push notification whilst the app is not running? 但是,当应用程序未运行时设备收到推送通知时,如何播放声音并让手机振动?

Fixed by sending the sounds file through an NSDictionary , as shown in the parse documention . 通过通过NSDictionary发送声音文件进行了修复,如解析文档中所示。

NSDictionary *data = @{
  @"alert" : @"Jet fuel proven to melt steal beams!",
  @"badge" : @"Increment",
  @"sounds" : @"cheering.caf"
};
PFPush *push = [[PFPush alloc] init];
[push setChannels:@[ @"Dank_Memes" ]];
[push setData:data];
[push sendPushInBackground];

In the data of your notification you need to add the sound key. 在通知的数据中,您需要添加sound键。 Here would be an example of a payload that would play a sound: 这是将播放声音的有效负载的示例:

"data": {
     "alert": "Good Morning please open our app",
     "sound": ""
} 

Here is more info on it. 是更多信息。

Here is info on how to customize the sound. 是有关如何自定义声音的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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