应用程序退出时自动增加applicationIconBadgeNumber

时间:2011-10-20 10:54:20

标签: iphone

程序员,我是目标C的新手。

我正在处理本地通知任务,我的任务是当用户退出应用程序并且他没有再次运行应用程序时,假设有一天,那么应用程序图标徽章编号应自动增加到1。如果它没有运行48小时,那么它应该增加并变为2(意味着我必须重复通知),依此类推。

我正在使用本地通知。我是这样做的:

- (void)applicationWillResignActive:(UIApplication *)application 
{
    [self launchNotification];
}


-(void)launchNotification
{
    NSDate *todaydate = [NSDate date];
    NSDate *firedates = [todaydate dateByAddingTimeInterval:10.0];

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

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit |     NSMinuteCalendarUnit | NSSecondCalendarUnit)
                                                   fromDate:firedates];

    [dateComps setHour:[timeComponents hour]];
    [dateComps setMinute:[timeComponents minute]];
    [dateComps setSecond:[timeComponents second]+10];

    localNotif.repeatInterval = NSSecondCalendarUnit;

    localNotif.soundName = UILocalNotificationDefaultSoundName;

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

    // Schedule the notification
    localNotif.applicationIconBadgeNumber = +1;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
}

我工作很长时间没找到出路。

0 个答案:

没有答案