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