iOS : Programmatically control the volume of Notification alert and sound theme

标签 ios iphone swift xcode apple-push-notifications

我有一个要求,例如,我们要通过应用程序设置通知声音和音量。这是因为我们的要求。有三种不同的状态——快乐、悲伤和正常。当用户获得一些积分时,我们会发送祝贺信息,当他失去一些积分时,我们也会发送该信息。促销也与其他一些信息有关。对于所有这些状态,我也想设置不同的通知声音和音量。感谢您的投入。泰

最佳答案

用于本地通知

func scheduleNotifications(inSeconds: TimeInterval, completion: @escaping (_ Success: Bool) ->()){
        ...
        notif.sound = UNNotificationSound.init(named: "CustomSound.mp3") 
        ...
}

对于推送通知

APS数据中应该有声音 key ,你的服务器需要发送要播放的文件名,

{
  aps =
  {
    alert = "message";
    sound = "sound file name.extension";
    badge = 1;
  };
}

关于iOS : Programmatically control the volume of Notification alert and sound theme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43270062/

相关文章:

iphone - 如何从 iOS 应用程序使用 REST API 验证 Microsoft SharePoint 站点

iphone - 使用 Core Data 在 UITableView 中显示 "No rows found"消息

ios - 无法将类型 '(String?, Bool, [AnyObject]?, NSError?) -> ()' 的值分配给

objective-c - 如何使用 AnyClass 对象中定义的类型在 Swift 中声明变量?

ios - 压缩从设备中获取或从库中选择的图像,iOS

ios - 如何将 NSDictionary 类型的对象添加到包含 NSDictionaryResultType 对象的 NSMutableArray?

objective-c - 远程关闭 iOS 推送通知

ios - 应用程序在 View Controller 中添加 @IBAction 时崩溃

ios - 在 iOS 中重新接收短信

ios - XMPP 如何在当前用户下线时收到通知或事件?