UNMutableNotificationContent
のsound
プロパティに設定するといけるようです。
再生できるフォーマットは以下を参考に↓
参考URL: Apple UNNotificationSound
しかしバグなのか実機では思ったように音が鳴らずデフォルトの音がなりました、シュミレーターでは再生されました。
※バッジも同じく、、、
UNNotificationSound not playing custom sound
最後のコメントでFixed in iOS 10.1 beta 2.
とあるので直ったのかも(未検証)
swift
1let content = UNMutableNotificationContent()
2content.sound = UNNotificationSound(named: "sample.m4a")
3content.badge = 10
4content.title = "Title"
5content.body = "Body"
6
7let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
8
9let requestIdentifier = "sampleRequest"
10
11let request = UNNotificationRequest(identifier: requestIdentifier,
12 content: content,
13 trigger: trigger)
14
15UNUserNotificationCenter.current().add(request) {
16 (error) in
17 print(error)
18}
環境: Xcode8, Swift3, iPhone7, iOS10.0.2
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/08 00:46