【发布时间】:2015-10-03 21:11:05
【问题描述】:
我正在使用 Swift 编码并尝试显示通知。它们确实出现了,但没有播放声音。我确实浏览了这个站点和其他站点,我的代码看起来与建议的解决方案相同,所以我不确定出了什么问题。
这是我的 AppDelegate.swift:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil
))
return true
}
和
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
var alert = UIAlertView()
alert.title = "Alert"
alert.message = notification.alertBody
alert.addButtonWithTitle("Dismiss")
alert.show()
}
这是我的 ViewConrtoller.swift 中的函数:
override func viewDidLoad() {
super.viewDidLoad()
var localNotification: UILocalNotification = UILocalNotification()
localNotification.soundName = "sample.wav";
localNotification.fireDate = NSDate(timeIntervalSinceNow: 2)
localNotification.alertAction = "TEST"
localNotification.alertBody = "Sound Test"
localNotification.applicationIconBadgeNumber = 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
【问题讨论】:
-
您看过哪些帖子?可以发一些链接吗?
-
我阅读了 Preparing Custom Alert Sounds 并将文件转换为 .caf 文件,并将文件添加到我的项目(文件夹中的 Created Resources -> Audio 文件夹),但它仍然不是在职的。有些帖子是这样的stackoverflow.com/questions/26734350/…和这个czetsuya-tech.blogspot.com/2014/08/…
标签: ios swift push-notification