0

ローカル通知の機能を取得するアプリケーションを開発しています。一致する条件がほとんどない場合は、ローカル通知を起動する必要があります。これで、ローカル通知とアクションの実行が完了しました。しかし、アプリケーションがフォアグラウンドまたはバックグラウンドであっても、「通知センター」で発生したすべての通知を表示する必要があります。

私は次のコードを使用しています:

didFinishLaunchingWithOptions メソッドで:

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}

一致する条件がほとんどない場合:

for (int i = 0; i < [arrayNotif count]; i++) {
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    [localNotif setAlertBody:[NSString stringWithFormat:@"%@", [[arrayNotif objectAtIndex:i] valueForKey:@"title"]]];
    [localNotif setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]];
    [localNotif setTimeZone:[NSTimeZone defaultTimeZone]];

    NSDictionary *dictionary = [NSDictionary dictionaryWithObject:[arrayNotif objectAtIndex:i] forKey:[NSString stringWithFormat:@"%@", [[arrayNotif objectAtIndex:i] valueForKey:@"id"]]];
    [localNotif setUserInfo:dictionary];

    localNotif.soundName = UILocalNotificationDefaultSoundName;
    [localNotif setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber] + 1];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    dictionary = nil;
}

didReceiveLocalNotification:メソッドによってすべての通知を取得します。アプリケーションのみがフォアグラウンドにあります。ここで、通知センターにすべての通知を表示したいと思います。

4

0 に答える 0