0

我正在尝试将此代码放在 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";标题上没有任何内容,而是标题为“通知”。

谢谢你...

4

1 回答 1

3

声音

您需要通过指定您自己的声音文件名或默认值来指定您想要的声音。从文档中

对于此属性,指定应用程序主包中声音资源的文件名(包括扩展名)或 UILocalNotificationDefaultSoundName 以请求默认系统声音。当系统显示本地通知的警报或标记应用程序图标时,它会播放此声音。默认值为 nil(无声音)。不支持持续时间超过 30 秒的声音。如果您指定的文件的声音播放时间超过 30 秒,则会播放默认声音。

标题

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

于 2013-09-23T16:39:12.063 回答