Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 每天从选择器中选择的时间触发本地通知_Iphone_Objective C - Fatal编程技术网

Iphone 每天从选择器中选择的时间触发本地通知

Iphone 每天从选择器中选择的时间触发本地通知,iphone,objective-c,Iphone,Objective C,在我的应用程序中,我想在每天的特定时间设置本地通知。时间是从时间选择器中选择的时间。是否有任何方法可用于此。请帮助我。您可以设置本地通知。 在苹果的示例代码中: - (void)scheduleNotificationWithItem:(ToDoItem *)item interval:(int)minutesBefore { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateCompon

在我的应用程序中,我想在每天的特定时间设置本地通知。时间是从时间选择器中选择的时间。是否有任何方法可用于此。请帮助我。

您可以设置本地通知。 在苹果的示例代码中:

- (void)scheduleNotificationWithItem:(ToDoItem *)item interval:(int)minutesBefore {
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:item.day];
    [dateComps setMonth:item.month];
    [dateComps setYear:item.year];
    [dateComps setHour:item.hour];
    [dateComps setMinute:item.minute];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = [itemDate addTimeInterval:-(minutesBefore*60)];
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@ in %i minutes.", nil),
         item.eventName, minutesBefore];
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);

    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:item.eventName forKey:ToDoItemKey];
    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}
您可以为特定的timstamp设置本地通知。 您必须在ApplicationIDFinishedLaunching中检查用户信息字典,以获取任何通知数据

你必须处理:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

只需将firedate指定为UIDatePicker中的日期,将NSDayCalendarUnit指定为repeatinterval:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];

if (localNotif == nil)
    return;

localNotif.fireDate = datePicker.date;
localNotif.timeZone = [NSTimeZone defaultTimeZone];

localNotif.alertBody = @"This is the Alert-Body Text"];
localNotif.alertAction = @"Button-Text";

localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

localNotif.repeatInterval = NSDayCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];