在按钮顶部显示UIlocalNotification徽章编号

时间:2014-11-03 17:34:08

标签: ios objective-c uibutton uilocalnotification

我是UILocalNotification概念的新手。

我有一个提醒按钮,通过点击它来调用UILocalNotification代码......

-(void)LocalNotificationMethod{
    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

    // Get the current date
    NSDate *pickerDate =  self.selectedDate;
    NSLog(@" self.selectedDate %@", self.selectedDate);
    // 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];


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

    // Notification details
    localNotif.alertBody = [_titleTextFieldObj text];
    // Set the action button
    localNotif.alertAction = @"View";

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

    // Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    localNotif.userInfo = infoDict;
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    //UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
    NSLog(@"notif %@",notificationArray);
    //[cell.textLabel setText:notif.alertBody];
    //[cell.detailTextLabel setText:[notif.fireDate description]];
    //NSDate *datee=notif.fireDate;
    //NSLog(@"notify date is %@",datee);
    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];



}

我收到警报。但我想在该提醒按钮中显示通知徽章。 如果我收到两个通知,那么我想在按钮中获取2badge数字。 不在应用程序图标中...... 任何人都可以帮助我......

1 个答案:

答案 0 :(得分:0)

尝试使用Core Graphics构建和呈现自定义徽章的CustomBadge。他们只是UIView个子类,因此您可以像使用任何其他UIView子类一样使用框架将它们布局。

您可以使用CocoaPod

在应用中添加Custom badge