简体   繁体   English

iOS推送通知 - 如何指定没有声音的警报和徽章?

[英]iOS Push Notifications- How to specify alert and badge with NO sound?

I am wondering how to send a Push Notification with NO sound. 我想知道如何发送没有声音的推送通知。

From Apple's website : 来自Apple的网站

The sound in this file is played as an alert. 此文件中的声音将作为警报播放。 If the sound file doesn't exist or default is specified as the value, the default alert sound is played. 如果声音文件不存在或默认值被指定为值,则播放默认警报声音。

This says that if I use "default" for the sound file or if I specify a sound file that does not exist, it will play the default alert sound. 这表示如果我对声音文件使用“default”,或者如果我指定一个不存在的声音文件,它将播放默认的警报声音。

But it does specifically state how to have no sound... If I just do not include a sound in the payload (leave it out), will this mean that there will be no sound played? 但它确实具体说明了如何没有声音...如果我只是不在有效载荷中包含声音(将其留下),这是否意味着不会播放声音?

Thanks 谢谢

If I just do not include a sound in the payload (leave it out), will this mean that there will be no sound played? 如果我只是没有在有效载荷中包含声音(将其留下),这是否意味着不会播放声音?

That's right. 那就对了。 Just don't include sound in the payload. 只是不要在有效载荷中包含sound Or, don't even register for sound notification type if you're never going to want to play sounds. 或者,如果您不想播放声音,甚至不要注册声音通知类型。

You should configure your App to receive the type of PN that you wish to accept, there are three options: 您应该将应用程序配置为接收您希望接受的PN类型,有三个选项:

  1. Display a short text message 显示简短的短信
  2. Play a brief sound 播放一个简短的声音
  3. Set a number in a badge on the app's icon 在应用程序图标的徽章中设置一个数字

You may use these three in any combination that you see fit, now all you need to do in your App is to registerForRemoteNotificationTypes as follows: 你可以在你认为合适的任何组合中使用这三个,现在你需要在app中做的就是registerForRemoteNotificationTypes,如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
 
    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
 
    return YES;
}

Select the appropriate option(s) in your case, once the app starts and registers for Push Notifications, a message will popup asking the user whether or not to accept Push Notifications. 在您的案例中选择适当的选项,一旦应用程序启动并注册推送通知,将弹出一条消息,询问用户是否接受推送通知。

When registering for notifications you do something like this i'm guessing? 注册通知时,你会做这样的事我猜吗?

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 

just don't include UIRemoteNotificationTypeSound. 只是不包括UIRemoteNotificationTypeSound。

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

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