如何使用Apple制作的铃声进行本地通知? (迅速)

时间:2016-02-17 18:33:10

标签: ios xcode swift localnotification

我正在开发一个应用程序,在一段时间后唤醒你,当它醒来的时候我想让本地通知播放Marimba铃声,我将如何在Swift代码中执行此操作? (我不想下载铃声的实际声音文件)

// create a new alarm/notification
    let notification: UILocalNotification = UILocalNotification()
    notification.category = "wakeUpAlarms"
    notification.alertAction = "turn off the alarm"
    notification.alertBody = "Time to wake up!"
    notification.fireDate = NSDate(timeIntervalSinceNow: 10)

// instead of UILocalNotificationDefaultSoundName, I want the sound name to 
// be one of the iPhone ringtones that are located in the "Sounds" page of 
// such as Marimba the settings app
    notification.soundName = UILocalNotificationDefaultSoundName

    UIApplication.sharedApplication().scheduleLocalNotification(notification)

1 个答案:

答案 0 :(得分:0)

您只能使用属于主要捆绑包的声音,这意味着您必须在提交到应用商店时将声音文件保留在应用内置版中。

  1. UILocalNotification Class Referencehttps://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/index.html
  2. Local and Push Notification Programming Guide https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103