ios - UILocalNotification 始终提供默认声音

标签 ios swift audio uilocalnotification

我想在交互式本地通知中添加自定义声音。我已经在appdelegate中编写了这段代码

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    scheduleNotification()
}
    func scheduleNotification() {
    //UIApplication.sharedApplication().cancelAllLocalNotifications()

    // Schedule the notification ********************************************
    if UIApplication.sharedApplication().scheduledLocalNotifications!.count == 0 {

        let notification = UILocalNotification()
        notification.alertBody = "Hey! Update your counters ;)"
        // let URLToMyFile = documentsURL.URLByAppendingPathComponent("notes_of_the_optimistic.caf")

        let ring: String = NSBundle.mainBundle().pathForResource("notes_of_the_optimistic", ofType: "caf")!
        print(ring)
        notification.soundName = ring
        notification.fireDate = NSDate()
        notification.category = categoryID
        notification.repeatInterval = NSCalendarUnit.Minute

        UIApplication.sharedApplication().scheduleLocalNotification(notification)
    }
}

我在我的项目中添加了notes_of_the_optimistic.caf 文件,但我的 nitification 始终给出默认声音。声音文件的长度是29秒。有哪位 friend 可以告诉我我缺少什么吗?

最佳答案

您不需要获取自定义声音的完整路径,您只需要具有文件格式的声音名称 like notification.soundName = "notes_of_the_optimistic.caf"

关于ios - UILocalNotification 始终提供默认声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700842/

相关文章:

swift - 如何减少 UnitConverter 中的小数点?

ios - AVAudioSession 与 AVPlayer : The 'Play' Icon in the status menu not showing when the AVPlayer player is playing

iphone - UICollectionView willDisplayCell 委托(delegate)方法?

ios - 从 Swift 中的不同类访问 ViewController 中的变量

iOS Safari 因提交大型帖子数据表单而崩溃

ios - SKStoreReviewController.requestReview() 无法在新的 App 版本上评分

ios - MonoTouch 错误 : "The Apple iPhone SDK not installed" after upgrade to iOS 5. 1

ios - 如何使用 ReactiveCocoa 处理无效 token

java - WAV音频无法从IntelliJ创建的JAR文件中播放

audio - 核心音频中如何选择音频输入设备?