从通知中删除声音 [英] Remove sound from notification

查看:42
本文介绍了从通知中删除声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个UISwitch,以便用户可以选择不从应用程序内部获取推送声音.是否可以?我试图重新注册却没有声音-

I'm trying to create a UISwitch so user can choose not to get push sounds from inside the app. Is it possible? i've tried to register again without sound -

+ (void)registerToNotificationWithoutSound
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeAlert)];
    }
}

所有操作都是禁用用户在iphone设置中打开/关闭声音之间切换的功能,但仍会记住当切换功能可用时用户选择的内容.

and all is does is disable the users ability to toggle between sound on/off in the iphone settings, but still remembers what the user chosen when the ability to toggle was available.

例如-如果用户从iphone设置中启用了推送声音,而不是从应用程序中禁用了推送声音-现在,他无法在iphone设置上看到或使用通知声音切换开关,但在接收到推送消息时仍然可以听到声音.

for example - if the user enables the push sound from the iphone settings and than disable it from the app - he now cant see or use ,the notification sound toggle switch, on the iphone settings but still get sound when receiving push.

谢谢

推荐答案

从客户端(iOS应用)无法实现.但是,您可以删除从服务器端(后端)发送的有效负载中的声音键,并且推送通知将保持静默状态.

It's not possible from the client side (iOS app). But, you can remove the sound key in the payload you send from your server side (backend) and the push notification will be silent.

使用默认声音:

{"aps":{"alert":"Hello","badge":1,"sound":"default","category":"your_category_key"}}

没有声音:

{"aps":{"alert":"Hello",徽章":1,"category":"your_category_key"}}

这篇关于从通知中删除声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆