【问题标题】:My remainder IPhone application getting delayed in seconds我剩余的 iPhone 应用程序在几秒钟内被延迟
【发布时间】:2013-10-25 07:14:01
【问题描述】:

我使用UIDatePickerNSLocalNotification 进行了余数申请。剩余的应用程序已准备好并正在运行,但剩余的应用程序每次都会在几秒钟后触发。

代码如下:

-(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];
    }

【问题讨论】:

    标签: iphone objective-c cocoa-touch uidatepicker


    【解决方案1】:

    我猜您的问题将出在 NSDateFormatter 上,因为您在其中添加了秒数,它也会返回秒数。因此会有几秒钟的延迟。

    将您的 NSDateFormatter 更改为

    @"dd-MM-YYYY HH:mm"

    解释:

    LocalNotification 将被设置为@"dd-MM-YYYY HH:mm:SS" 格式,因此我们必须将其转换为@"dd-MM-YYYY HH:mm" 格式(没有秒数)。

    【讨论】:

      猜你喜欢
      • 2019-10-25
      • 2015-03-22
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多