iOS开发 如何只想在后台推送通知声音,前台不推送声音

下面这个示例是在前台中也能收到声音推送,要想在前台中不推送声音,只需要设置为completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
   // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以设置
    completionHandler(UNNotificationPresentationOptionBadge| UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);

}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容