2016-07-30 6 views
2

CloudKitのプッシュ通知を使用しています。ここで私はスウィフト3の前に使用したものである: UNNotificationSoundのサウンド名

'UILocalNotificationDefaultSoundName' was deprecated in iOS 10.0: Use UserNotifications Framework's +[UNNotificationSound defaultSound]

は、だから私は、私のXcodeにUserNotificationフレームワークを追加しました:

notification.soundName = UILocalNotificationDefaultSoundName 

しかし

(通知がCKNotificationInfoである)、これは私に警告を与えます私のViewControllerにインポートしました。私は、これを試してみました:

notification.soundName = UNNotificationSound.default() 

しかし、これは私にエラーを与える:

Cannot assign value of type 'UNNotificationSound' to type 'String?'

だからデフォルトのサウンドはUNNotificationSoundですが、私は、音名が必要です。サウンドからサウンド名を取得するにはどうすればよいですか?ありがとう!

import UserNotifications 

let content = UNMutableNotificationContent() 
content.sound = UNNotificationSound.default() 

let request = UNNotificationRequest(identifier: "id", content: content, trigger: nil) 

答えて

1

は新しいUserNotificationsフレームワークを使用しますそれのために更新されました。

現時点では、UILocalNotificationDefaultSoundNameが通常返したものを使用し、"default"を使用することをおすすめします。

+0

これは正確に私が探していたものではありません...私は 'UNNotificationRequest'が必要であるとは思わない。また、残念ながらcontent.soundは取得できません。 – penatheboss

+2

.soundはUNNotificationContentのget-onlyですが、UNMutableNotificationContentを使用する場合は、使用するサウンドに設定することができます。 – gohnjanotis

2

悲しいことに、私はここで答えは、我々は新しいUserNotificationsフレームワーク、CloudKitとCKNotificationInfoで素晴らしいものをたくさん得ているにもかかわらず、特に取得していないということだと思う: