通知错误或其他

时间:2015-05-30 15:16:32

标签: ios objective-c uilocalnotification

我在循环中生成通知,为什么本地通知操作仅显示在前2个已创建的通知中?

以下是代码:

UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init];
        notificationAction1.identifier = NotificationActionOneIdent;
        notificationAction1.title = NSLocalizedString(@"Marcar como Feito", nil) ;
        notificationAction1.activationMode = UIUserNotificationActivationModeBackground;
        notificationAction1.destructive = NO;
        notificationAction1.authenticationRequired = NO;

        UIMutableUserNotificationAction *notificationAction2 = [[UIMutableUserNotificationAction alloc] init];
        notificationAction2.identifier = NotificationActionTwoIdent;
        notificationAction2.title = @"Snooze";
        notificationAction2.activationMode = UIUserNotificationActivationModeBackground;
        notificationAction2.destructive = YES;
        notificationAction2.authenticationRequired = YES;

        UIMutableUserNotificationAction *notificationAction3 = [[UIMutableUserNotificationAction alloc] init];
        notificationAction3.identifier = NotificationActionThreeIdent;
        notificationAction3.title = @"Reply";
        notificationAction3.activationMode = UIUserNotificationActivationModeForeground;
        notificationAction3.destructive = NO;
        notificationAction3.authenticationRequired = YES;

        UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
        notificationCategory.identifier = NotificationCategoryIdent;
        [notificationCategory setActions:@[notificationAction1,notificationAction2,notificationAction3] forContext:UIUserNotificationActionContextDefault];
        [notificationCategory setActions:@[notificationAction1,notificationAction2,notificationAction3] forContext:UIUserNotificationActionContextMinimal];

        NSSet *categories = [NSSet setWithObjects:notificationCategory, nil];

        UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];

        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

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

        int r = rand() % 30;
        localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:r];
        localNotification.alertBody = @"test";
        localNotification.userInfo = nil;
        localNotification.category = NotificationCategoryIdent; //Same as category identifier
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

这让我抓狂:)

0 个答案:

没有答案