【问题标题】:iOS5 local notification custom sound xcode iOS iPhone objective-c XcodeiOS5本地通知自定义声音xcode iOS iPhone Objective-c Xcode
【发布时间】:2012-03-14 20:04:52
【问题描述】:

我正在尝试设置自定义本地通知声音,如下所示:

UILocalNotification *notification = [UILocalNotification new];
notification.timeZone = [NSTimeZone systemTimeZone];
notification.fireDate = date;

notification.alertAction = @"123"; 
notification.alertBody = @"123";

//!!!
notification.soundName = @"Glass.aiff";

alarmID=[NSString stringWithFormat:@"%i", arrayAlarms.count];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmID forKey:@"id"]; 
notification.userInfo = infoDict; 
notification.repeatInterval=NSWeekCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

但我只听到默认声音。我正在 ios5 上测试应用程序。非常感谢您提前提供的帮助,对不起我的英语。

【问题讨论】:

    标签: objective-c audio ios5 notifications uilocalnotification


    【解决方案1】:

    自定义通知声音限制在 30 秒以内。如果您的声音比此 iOS 更长,则会播放默认声音。这可能是你的问题吗?

    有关更多信息,请参见此处。 https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

    “自定义声音在播放时必须小于 30 秒。如果自定义声音超过该限制,则会播放默认系统声音。”

    【讨论】:

    • 不,问题似乎在于'notification.soundName = @"Glass.aiff";'没有正确地发出声音。看起来声音的名称是不够的。因为 Glass.aiff 的声音,IS 不到 30 秒。看来玩 Glass.aiff 的唯一方法是将其包含在您的应用程序中。这是相当愚蠢的,因为您必须包含 iOS 已经包含在您设备中的文件! (好吧,它不是一个大文件,但仍然......想象一下,如果您希望您的用户能够从所有可用的(iOS)声音中进行选择。您不能!您必须包括所有(14)个!)
    • 此页面可能会有所帮助:iphonedevwiki.net/index.php/AudioServices 也许它实际上并没有在文件系统上调用 Glass,实际上类似于“sms-received2.caf”?一旦你找到你想要的声音文件名,我相信这个答案可能会对你有所帮助:stackoverflow.com/a/7831768/387317
    • 那个(第二个链接)有效,但仅适用于 3 个(是 3 个)声音。 .caf 声音(第一个链接)无处可寻。所以我们回到了第 1 格(几乎)。
    【解决方案2】:

    检查你的语法,它是错误的。看看这个,

    notification.soundName = "Glass.aiff";

    【讨论】:

      【解决方案3】:

      仍然可以使用 UILocalNotificationDefaultSoundName 作为默认的本地通知声音。

      【讨论】:

        【解决方案4】:

        notification.soundName = @"Glass.aiff";

        应该可以。确保声音(Glass.aiff)实际上在您的应用程序包中,并且小于 30 秒。我们无法设置不存在于我们应用程序包中的自定义声音,即来自 Document 文件夹等。

        【讨论】:

          猜你喜欢
          • 2021-11-15
          • 1970-01-01
          • 1970-01-01
          • 2021-07-01
          • 1970-01-01
          • 2018-01-06
          • 2011-11-02
          • 2017-03-10
          • 1970-01-01
          相关资源
          最近更新 更多