我正在练习在IOS 7上开发Alarm应用程序。 Alarm time up on IOS7 但是,我在锁定屏幕上停留在本地通知,就像这样。 My notification 我做了一些代码:
在我的AppDelegate.m
中我的代码
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
// Handle launching from a notification
UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
....
..in my ViewController.m..
[self scheduleLocalNotificationWithDate:correctDate];
....
(void)scheduleLocalNotificationWithDate:(NSDate *)fireDate {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = fireDate;
localNotification.alertBody = [NSString stringWithFormat:@"Alert Fired at %@", fireDate];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = numberReminder;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
谁可以帮忙做到这一点?
由于
答案 0 :(得分:0)
第三方应用程序不会像系统闹钟应用程序那样出现在锁定屏幕上 - 您的应用程序只能生成普通通知。如果您希望添加API以获得全屏提醒样式,则可以尝试filing an enhancement request。
答案 1 :(得分:-1)
if([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(notification) {
application.applicationIconBadgeNumber = 0;
}
在View Controller.m中调用此函数
- (void) Notify {
NSDate *fireDate = [[NSDate alloc]init];
fireDate = self.datePicker.date;
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *dateComp = [cal components:(NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond) fromDate:fireDate];
NSDate *dd = [cal dateByAddingComponents:dateComp toDate:fireDate options:0];
UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setFireDate:dd];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}