从通知中移除声音

我试图创build一个UISwitch,所以用户可以select不从应用程序内部获取推送声音。 可能吗? 我试图无声地再次注册 –

+ (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)]; } } 

而且所有的function都是禁用用户在iPhone设置中开启/closures声音的能力,但仍然记得用户在切换function可用时所select的function。

例如 – 如果用户从iphone设置中启用推送声音,并从应用程序中禁用它 – 他现在无法看到或使用iphone设置上的通知声音切换开关,但在接收推送时仍然听起来很健康。

谢谢

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

默认声音:

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

没有声音:

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