我对 iPhone 的警报功能(本地通知)有点困惑,我还没有找到明确的答案。我想创建像闹钟(甚至是新邮件)这样的功能。具体来说,如果设备处于睡眠状态,它会被嗡嗡声或声音唤醒。您看不到的弹出消息(因为设备处于睡眠状态)的用处要小得多。但是,似乎使用 UILocalNotification 服务,这似乎并没有发生。我还没有查看推送通知,但它们似乎是为了别的。
我可能遗漏了一些东西(我希望如此),所以知道的人请为我澄清这个问题。闹钟、邮件和脸书都是这样做的。
我现在正在做的代码片段:
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:0];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
alarm.fireDate = itemDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.repeatInterval = NSDayCalendarUnit;
alarm.soundName = @"alarmsound2.m4a";
alarm.alertBody = NSLocalizedString(@"WakeUp", @"");
alarm.hasAction = YES;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"alarm_notify" forKey:@"type"];
alarm.userInfo = infoDict;
[app scheduleLocalNotification:alarm];
[alarm release];