开发者

firing a local notification on everyday from time selected from picker

In my app i want to set up a local notification on ev开发者_如何学Ceryday at a particular time.Time is the one that selected from a Time picker.Is there any method for this.Plese help me.


Just specify the firedate as the date from your UIDatePicker and NSDayCalendarUnit as the 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];


you can set Local Notifications. Right out of apple's sample code:

- (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];
}

you can set a local notification for a specific timstamp. you have to check userinfo dictionary in applicationDidFinishedLaunching for any notification data.

you have to handle:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜