1

UIDatePickerと を使用して剰余アプリケーションを作成しましたNSLocalNotification。残りのアプリは準備ができて動作していますが、残りは毎回数秒後にトリガーされます。

コードは次のとおりです。

-(void)addRemainder
{

    NSDateFormatter *dateform=[[NSDateFormatter alloc]init];
    dateform.dateFormat = @"dd-MM-yyyy HH:mm";
    NSString *formattedDate = [dateform stringFromDate:datePicker.date];
    date=[dateform dateFromString:formattedDate];
    str=[dateform stringFromDate:date];

    if(textField1.text!=nil)
    {

        notification = [[UILocalNotification alloc] init];
        notification.fireDate = date;
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.alertBody = textField1.text;
        notification.alertAction=@"Show me the item";
        notification.soundName = UILocalNotificationDefaultSoundName;
        NSUInteger nextBadgeNumber = [[[UIApplication sharedApplication]    scheduledLocalNotifications] count] + 1;
        notification.applicationIconBadgeNumber = nextBadgeNumber;
        notification.repeatInterval = NSDayCalendarUnit;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

    }

    if ([remainderr isEqualToString:@"edit"])
    {
        [remainder replaceObjectAtIndex:([index integerValue]) withObject:textField1.text];
        [TimeDate replaceObjectAtIndex:([index integerValue]) withObject: str];
        [self.navigationController popViewControllerAnimated:YES];
    }
4

1 に答える 1

0

秒を追加したので、問題は NSDateFormatter にあると思います。秒も返されます。したがって、秒の遅延があります。

NSDateFormatter を次のように変更します

@"dd-MM-YYYY HH:mm"

説明:

LocalNotification は @"dd-MM-YYYY HH:mm:SS" の形式に設定されるため、@"dd-MM-YYYY HH:mm" (秒なし) の形式に変換する必要があります。

于 2013-10-25T07:18:05.047 に答える