从通知中删除声音

时间:2015-01-27 09:36:33

标签: ios iphone notifications

我正在尝试创建一个UISwitch,因此用户可以选择不从应用程序内部获取推送声音。 可能吗?我试图在没有声音的情况下重新注册 -

+ (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设置中在声音开/关之间切换的能力,但仍然记得用户在切换能力可用时选择的内容。

例如 - 如果用户从iphone设置启用推送声音,而不是从应用程序禁用它 - 他现在无法看到或使用,通知声音切换开关,在iPhone设置上但在接收推送时仍然会发出声音。

感谢

1 个答案:

答案 0 :(得分:5)

从客户端(iOS应用程序)无法实现。但是,您可以删除从服务器端(后端)发送的有效负载中的声音密钥,推送通知将保持静默。

使用默认声音:

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

没有声音:

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

相关问题