UILocalNotification每天两次 [英] UILocalNotification Twice every day

查看:112
本文介绍了UILocalNotification每天两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每天两次点击当地通知,例如:每天早上7点,每天早上6点,所以任何人都可以帮我,我该怎么办?

I want to fire local notification twice everyday like for ex:- morning 7am and evening 6pm everyday so can anyone please help me how can i do that?

无法设置自定义时间点火本地通知已查看每个地方,但没有任何帮助,一天两次火本地通知,如果有任何帮助将很高兴地欣赏

unable to set custom time to fire the local notification have looked every where but nothing helpful for fire local notification twice in a day if any help will appreciate graetly

提前谢谢:)

这是我使用本地通知的代码的和平,但它根本没有解雇:(

this is the peace of code i am using local notification but it's not firing at all :(

- (void)scheduleNotification
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];    
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {       
        NSString *end = @"2013-09-20 11:24:00 +0000";
        NSDate *endDate = [self convertStringToDate:end];
        NSLog(@"end date :%@", endDate);

        UILocalNotification *notif = [[cls alloc] init];
    notif.fireDate = endDate;
    notif.timeZone = [NSTimeZone defaultTimeZone];

    notif.alertBody = @"Did you forget something?";
    notif.alertAction = @"Show me";
    notif.soundName = UILocalNotificationDefaultSoundName;
    notif.applicationIconBadgeNumber = 1;

    notif.repeatInterval = NSDayCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];
    [notif release];
    }
}


推荐答案

最后获得解决方案如何在早上7点和下午6点设置 UILocalNotification 并每天重复它希望它有助于谁在通知上寻找相同的解决方案

Finally Got the solution how to set UILocalNotification for 7am and 6pm and repeat it daily hope it help who are looking fore same solutions on notification

-(void)scheduleNotification
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {      
        NSDate *now = [NSDate date];
        NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
        NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
        [components setHour:7];
        [components setMinute:0];
        NSDate *today7am = [calendar dateFromComponents:components];

        UILocalNotification *notif = [[cls alloc] init];
        notif.fireDate = today7am;
        notif.timeZone = [NSTimeZone defaultTimeZone];
        notif.repeatCalendar = [NSCalendar currentCalendar];
        notif.alertBody = @"Did you forget something?";
        notif.alertAction = @"Show me";
        notif.soundName = UILocalNotificationDefaultSoundName;
        notif.applicationIconBadgeNumber = 1;       
        notif.repeatInterval = NSDayCalendarUnit;

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


        NSCalendar *calendar2 = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
        NSDateComponents *components2 = [calendar2 components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
        [components2 setHour:18];
        [components2 setMinute:0];
        NSDate *today6pm = [calendar2 dateFromComponents:components2];

        UILocalNotification *notif2 = [[cls alloc] init];
        notif2.fireDate = today6pm;
        notif2.timeZone = [NSTimeZone defaultTimeZone];
        notif2.repeatCalendar = [NSCalendar currentCalendar];
        notif2.alertBody = @"Did you forget something2?";
        notif2.alertAction = @"Show me2";
        notif2.soundName = UILocalNotificationDefaultSoundName;
        notif2.applicationIconBadgeNumber = 1;
        notif2.repeatInterval = NSDayCalendarUnit;

        [[UIApplication sharedApplication] scheduleLocalNotification:notif2];
        [notif2 release];
    }
}

这篇关于UILocalNotification每天两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆