2

我有一个应用程序,我必须在其中使用警报视图,我知道它无法设置它,所以通知以警报视图样式出现。我如何设置它,如果用户点击我可以接收本地通知,它将自动设置为警报。

4

1 回答 1

1

您可以简单地UILocalNotification使用我的自定义方法进行设置..

- (void) scheduleAlarm:(NSString *)PaymentTitle FireDate:(NSDate *)tempFireDate {

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];


    NSDate *pickerDate = tempFireDate; //Set yourDate here

    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit )
  fromDate:pickerDate];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
  fromDate:pickerDate];
    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
//    [dateComps release];//comment it if use ARC

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

// Notification details
    localNotif.alertBody =@"Write your Message";
// Set the action button
    localNotif.alertAction = @"View";

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

// Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"iClientManagement" forKey:@"App"];
    localNotif.userInfo = infoDict;

// Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
//    [localNotif release];//cxomment it if use ARC
}

在我的博客上查看我的这个方法

另请参阅此波纹管链接中的另一个完整演示以进行显示UILocalNotifications

iphone 编程教程本地通知

于 2013-07-29T13:11:41.110 回答