如何访问默认的 iOS 声音以将其设置为通知声音?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11776737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:32:56  来源:igfitidea点击:

How can I access default iOS sound to set it as notification sound?

iphoneobjective-ciosnotificationsuilocalnotification

提问by user1367471

How can I access default iOS sound (Tri-tone, Chime, Glass, Horn, Bell, Electronic...) to set it as local notification sound?

如何访问默认的 iOS 声音(Tri-tone、Chime、Glass、Horn、Bell、Electronic...)以将其设置为本地通知声音?

I've created local notification, everything works but with default sound (which is Tri-tone). I want to use Chime or another

我创建了本地通知,一切正常,但使用默认声音(三音)。我想使用 Chime 或其他

I only know how to use my own sound files:

我只知道如何使用我自己的声音文件:

localNotif.soundName = @"sound.wav";

回答by bitmapdata.com

check out thissite.

看看这个网站。

If you want to play a Default System Sound. refer a following code, but private Frameworks. you will be rejected.

如果您想播放默认系统声音。参考以下代码,但私有框架。你会被拒绝。

AudioServicesPlaySystemSound(1004);

and check out other thissample code (No private frameworks. supported a Apple).

并查看其他示例代码(没有私有框架。支持 Apple)。

回答by Ben Flynn

System sounds are not available you your app, unfortunately. From the docs:

不幸的是,您的应用程序无法使用系统声音。从文档

Note: System-supplied alert sounds and system-supplied user-interface sound effects are not available to your iOS application. For example, using the kSystemSoundID_UserPreferredAlert constant as a parameter to the AudioServicesPlayAlertSound function will not play anything.

注意:系统提供的警报声音和系统提供的用户界面音效对您的 iOS 应用程序不可用。例如,使用 kSystemSoundID_UserPreferredAlert 常量作为 AudioServicesPlayAlertSound 函数的参数将不会播放任何内容。

Update

更新

While Apple does say you can't access system sounds, I suppose they must mean that you can't access them for your own purposes, but I see that UILocalNotification.h provides:

虽然 Apple 确实说您无法访问系统声音,但我想它们一定意味着您无法出于自己的目的访问它们,但我看到 UILocalNotification.h 提供:

UIKIT_EXTERN NSString *const UILocalNotificationDefaultSoundName; 

"Identifies the default system sound to play when a notification alert is displayed. You assign this value to the soundName property." I am now using this in my app and it seems to work fine.

“标识显示通知警报时播放的默认系统声音。您将此值分配给 soundName 属性。” 我现在在我的应用程序中使用它,它似乎工作正常。

回答by user2212412

Audio services are not private. The methods are documented in the developers reference guide and referenced in the Multimedia Programming guide.

音频服务不是私有的。这些方法记录在开发人员参考指南中,并在多媒体编程指南中引用。

All you need to do if figure out the reference id of the sound you want to play.

如果找出您要播放的声音的参考 ID,您只需要做的就是。