唤醒应用程序的LocalNotifiction

时间:2012-08-30 11:04:28

标签: iphone uilocalnotification

在我的应用程序中,我希望在特定时间设置本地通知,如果我的应用程序从后台杀死,如果我的应用程序处于运行状态,那么我不想显示本地通知

我已编写本地通知代码

NSCalendar *calendar1 = [NSCalendar autoupdatingCurrentCalendar];

        // Get the current date
        NSDate *pickerDate1 =self.dateEvening;//[self.dateEvening dateByAddingTimeInterval:60*1];// [self.pickerView date];

        // Break the date up into components
        NSDateComponents *dateComponents1 = [calendar1 components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) 
                                                       fromDate:pickerDate1];
        NSDateComponents *timeComponents1 = [calendar1 components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) 
                                                       fromDate:pickerDate1];


        NSDateComponents *dateComps1 = [[NSDateComponents alloc] init];
        [dateComps1 setDay:[dateComponents1 day]];
        [dateComps1 setMonth:[dateComponents1 month]];
        [dateComps1 setYear:[dateComponents1 year]];
        [dateComps1 setHour:[timeComponents1 hour]];

        [dateComps1 setMinute:[timeComponents1 minute]];
        [dateComps1 setSecond:[timeComponents1 second]];
        NSDate *itemDate1 = [calendar1 dateFromComponents:dateComps1];
        [dateComps1 release];

        UILocalNotification *localNotif1 = [[UILocalNotification alloc] init];
        if (localNotif1 == nil)
            return;
        localNotif1.fireDate = itemDate1;
        localNotif1.timeZone = [NSTimeZone defaultTimeZone];
        localNotif1.alertBody = @"Open application";


        localNotif1.alertAction = @"View";

        localNotif1.soundName = UILocalNotificationDefaultSoundName;




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

如果应用程序将从后台关闭,但上面的代码工作正常,但如果我的应用程序处于运行状态,那么我不希望触发本地通知。

0 个答案:

没有答案