1

アプリケーション バッジ番号で今日の日付を表示しようとしています。この日付は、アプリケーションがローカル通知を起動したときに更新する必要がありますが、問題はローカル通知が日付を更新しないことです。私のプロジェクトが作成された日の日付のみを表示します! ここに私のコードがあります:

- (void) viewDidLoad {

[self notification];

}

    - (void) notification  {


        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        NSDate *now = [NSDate date];    
        NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit ) fromDate: now];

        [componentsForFireDate year];
        [componentsForFireDate month];
        [componentsForFireDate day];
        [componentsForFireDate setHour:1];
        [componentsForFireDate setMinute:2];
        [componentsForFireDate setSecond:1];

        NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];

                UILocalNotification *notification = [[UILocalNotification alloc]init];
                notification.fireDate = fireDateOfNotification;
                notification.timeZone = [NSTimeZone localTimeZone];                    notification.repeatInterval= NSDayCalendarUnit; 


                NSString *date = [self showGregorianFullDate];

                notification.alertAction = @"View";
                notification.soundName = UILocalNotificationDefaultSoundName;


        //updating badge number :

                NSCalendar* Calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
                NSDateComponents *Components = [Calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )fromDate:[NSDate date]];

                int a = [Components day];
                notification.applicationIconBadgeNumber = a; 

            [[UIApplication sharedApplication] scheduleLocalNotification:notification];

    }
4

2 に答える 2

1

この 1 つの通知だけをスケジュールしますか? 通知が発生すると、コードを実行できなくなります。アプリが開いている場合は、通知を処理できます。ユーザーが通知に対してアクションを実行すると、再び処理する機会が与えられます。

この通知は、バッジ番号を特定の日付番号に設定するようにプログラムされています。その数は固定数です。通知が発生したときに自動的に変更されることはありません。

アプリケーション バッジは、多数の未処理の通知を表示するように設計されているため (ヒューマン インターフェイス ガイドラインに従って)、日付を表示するのに最適な場所ではない場合があります。また、アプリ ストアのレビュー ガイドラインを見ると、ヒューマン インターフェース ガイドラインに記載されていない方法でシステム提供のアイテムを使用するアプリは、アプリ ストアから拒否される可能性があります。

この道を進む場合は、Local Notification Programming Guideを参照してください。各アプリで 64 個のローカル通知をスケジュールできること、およびバッジ番号を翌日に更新するには、毎日 1 つスケジュールする必要があることを示しています。これは、ユーザーが 65 日間アプリを開かない場合、バッジ番号が間違っていることを意味し、ユーザー アラート用のローカル通知も残っていないことを意味します。

于 2012-04-18T16:38:13.417 に答える
-1

このようcomponentsForFireDatenotification.applicationIconBadgeNumber...

//updating badge number :
        int a = [componentsForFireDate day];
        notification.applicationIconBadgeNumber = a; 

applicationIconBadgeNumber問題は、通知を作成するときに事前に決定する必要があるということです。から日を取得する[NSDate date]と、通知が発生した日ではなく、通知を作成した日が表示されます。

于 2012-05-03T08:57:45.080 に答える