提醒不起作用
Reminder is not working
我想按时间提醒用户,但是用这个代码无法实现,请给我一个solution.This是我的代码:
NSDate *pickerDate = [self.StartDate date];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
NSDate *date1=[pickerDate dateByAddingTimeInterval:60];
notifyAlarm.fireDate = date1;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
//notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval =NSCalendarUnitWeekday;
notifyAlarm.soundName =UILocalNotificationDefaultSoundName;
notifyAlarm.alertBody =self.EventText.text;
//notifyAlarm.alertLaunchImage=@"in.png";
[app scheduleLocalNotification:notifyAlarm];
[self dismissViewControllerAnimated:YES completion:nil];
在appdelegate.m的didFinishLaunch方法中写这段代码
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}
我想按时间提醒用户,但是用这个代码无法实现,请给我一个solution.This是我的代码:
NSDate *pickerDate = [self.StartDate date];
UIApplication* app = [UIApplication sharedApplication];
UILocalNotification* notifyAlarm = [[UILocalNotification alloc] init];
NSDate *date1=[pickerDate dateByAddingTimeInterval:60];
notifyAlarm.fireDate = date1;
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
//notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval =NSCalendarUnitWeekday;
notifyAlarm.soundName =UILocalNotificationDefaultSoundName;
notifyAlarm.alertBody =self.EventText.text;
//notifyAlarm.alertLaunchImage=@"in.png";
[app scheduleLocalNotification:notifyAlarm];
[self dismissViewControllerAnimated:YES completion:nil];
在appdelegate.m的didFinishLaunch方法中写这段代码
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound)];
}