ios - 通知有效但没有声音

标签 ios notifications

我试图将此代码放在 AppDelegate.m 下以测试本地通知:

- (void)applicationDidEnterBackground:(UIApplication *)application
{    
    NSDate *alertTime = [[NSDate date]dateByAddingTimeInterval:5];
    UIApplication* thisApp = [UIApplication sharedApplication];
    UILocalNotification* notify = [[UILocalNotification alloc] init];
    if (notify){
        notify.fireDate = alertTime;
        notify.timeZone = [NSTimeZone defaultTimeZone];
        notify.repeatInterval = 0;
        notify.alertBody = @"This is notification";
        [thisApp scheduleLocalNotification:notify];
    }
}

但我没有像其他应用程序一样听到任何声音。我们应该提供自己的声音吗?我们不能在通知中使用 Apple 原生声音吗?

以及如何设置通知的“标题文本”?因为我看到的只是 notify.alertBody = @"This is notification";,它不会在标题上产生任何内容,而是将“Notification”作为标题。

谢谢你...

最佳答案

声音

您需要通过指定您自己的声音文件名或默认值来指定您想要的声音。 From the documentation :

For this property, specify the filename (including extension) of a sound resource in the application’s main bundle or UILocalNotificationDefaultSoundName to request the default system sound. When the system displays an alert for a local notification or badges an application icon, it plays this sound. The default value is nil (no sound). Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead.

标题

您不能修改通知的标题。它始终是您的应用名称,以便用户确切知道通知的来源。

关于ios - 通知有效但没有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964364/

相关文章:

iphone - 如何访问附加到 UIGestureRecognizer 的选择器的名称?

java - 非 Activity 类的Android通知

python - 使用 python 发送谷歌视频群聊通知

ios - Xcode ARC 转换工具问题

ios - 在 UIScrollView 上放置自定义图层

ios - 从 String Swift 2 Issue 获取数字

php - 有没有办法在 Windows 和 Linux 上使用 php 检测文件夹中的更改?

android - Android 通知操作按钮中的图标大小是多少?

IOS 推送通知 smartface 4.3 注册和远程 token

objective-c - 提高代码执行速度