1

我已经用 1 个视图控制器启动了一个应用程序。在应用程序委托中,我想在应用程序启动后将通知发送 1 分钟

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[phil_croweViewController alloc] initWithNibName:@"phil_croweViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    NSDate *mydate = [NSDate date];
    NSTimeInterval secondsInEightHours = 60;
    NSDate *dateOneMinsAhead = [mydate dateByAddingTimeInterval:secondsInEightHours];

    timeInTwoMinutes = [NSDateFormatter localizedStringFromDate:dateOneMinsAhead dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    localNotif.fireDate = dateOneMinsAhead;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.alertBody = @"alert";
    localNotif.alertAction = @"View";
    localNotif.soundName = UILocalNotificationDefaultSoundName;
    localNotif.applicationIconBadgeNumber = 1;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    NSLog(@"alert scheduled");


    return YES;
}

除了 applicationBadgeNumber 没有显示 1 之外,这工作正常。我想了解 applicationBadgeNumber 的作用吗?是红色圆圈里面有数字吗??

4

1 回答 1

0

很可能是因为您的应用程序的“徽章应用程序图标”设置未在新通知中心打开。

在此处输入图像描述

转到设置 > 通知。在“通知中心”部分或“不在通知中心”部分中找到您的应用,然后点击它。然后打开“徽章应用程序图标”设置。p/s:如果你的应用不在通知中心也没关系(即通知中心=OFF);徽章图标设置确实生效

于 2012-06-16T08:30:24.890 回答