2

通知の投稿をたくさん読みましたが、どういうわけかどこかで間違っているので、この質問を投稿します。アプリで毎日午前 9 時に通知を受け取りたい。午前 9 時に問題なく受信できますが、問題は午前 2 時にも同じ通知を受信することです。次のコードで試します。誰が私がどこで間違っているのか教えてもらえますか? それともios6の問題ですか?あらゆる種類の助けをいただければ幸いです。ありがとうございました。

    NSString *day =@"9:00 AM";
    NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init]autorelease];
    [dateFormat setDateFormat:@"hh:mm a"];
    //NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    //[dateFormat setTimeZone:gmt];
    NSDate *today=[dateFormat dateFromString:day];
    NSLog(@"string %@ & date %@",day,today);
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil)
    {
        // delObj.QCouter=delObj.QCouter+1;

        //[[UIApplication sharedApplication] cancelAllLocalNotifications];
        notif = [[cls alloc] init];
        notif.fireDate =today;
        notif.timeZone = [NSTimeZone systemTimeZone];
         NSLog(@"timeZone %@ ",[NSTimeZone systemTimeZone]);
        notif.alertBody = @"You have a new letter ";
        notif.alertAction = NSLocalizedString(@"View", nil);;
        notif.soundName = @"Ding3.wav";
        notif.applicationIconBadgeNumber = 1;
        notif.repeatInterval = NSDayCalendarUnit;
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"Status"];
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"You have a notifiaction"
                                                                       forKey:kRemindMeNotificationDataKey];
        notif.userInfo = userDict;
        // NSLog(@"userInfo %@",notif.userInfo);
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
        [[NSUserDefaults standardUserDefaults] setObject:@"CurrentDay" forKey:@"DayChange"];
       }
4

2 に答える 2

1

こんにちは次のコードを試してください:-

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    NSDate *date = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
    NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
    [components setHour: 9];
    [components setMinute: 0];
    [components setSecond: 0];

    NSDate *today = [gregorian dateFromComponents: components];
    [gregorian release];

    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil)
    {
        notif = [[cls alloc] init];
        notif.fireDate =today;
        notif.alertBody = @"You have a new letter ";
        notif.alertAction = NSLocalizedString(@"View", nil);;
        notif.soundName = @"Ding3.wav";
        notif.applicationIconBadgeNumber = 1;
        notif.repeatInterval = NSDayCalendarUnit;
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"Status"];
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"You have a notifiaction"
                                                                       forKey:kRemindMeNotificationDataKey];
        notif.userInfo = userDict;
        // NSLog(@"userInfo %@",notif.userInfo);
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
        [[NSUserDefaults standardUserDefaults] setObject:@"CurrentDay" forKey:@"DayChange"];
       }
于 2013-03-13T07:03:58.833 に答える
1

シミュレータまたは実機?

シミュレーターには、1 つの通知の 2 つの「発火」を生成する既知のバグがあります。そのような場合は、物理デバイスで試して、同じ動作が発生するかどうかを確認してください。面倒ですが、アプリの実際の問題ではありません。(もちろん、シミュレーターだと仮定して!)

この質問を参照してください: iOS – 同じ通知に対して UILocalNotification が 2 回発生しました

「シミュレーターにない」に基づいて編集します。

通知をスケジュールした後にこれへの呼び出しを追加してみて、コードの他の部分が、気付いていない別のスケジュールされた項目に滑り込んでいないかどうかを確認してください。

- (void) _debug_logExistingToConsole
{
    if (LOG) NSLog(@"Notifications set is now: \n");
    UIApplication *Ap = [UIApplication sharedApplication];
    NSArray* arr = [Ap scheduledLocalNotifications];
    if (LOG) NSLog(@"%@", arr);
}
于 2013-03-07T10:30:03.760 に答える