是否可以在定时后设置uilocalnotification的alert body

发布于 2025-01-08 08:29:59 字数 1588 浏览 1 评论 0原文

我遇到了 UILocalNotifications 的问题。我的问题是——是否可以在安排后设置 uilocalnotification 的警报正文?

提前致谢。

-------------------------------------
// scheduling uilocalnotification 
localNotification = [[UILocalNotification alloc]init];
 NSDate *currDate1 = [defaults objectForKey:@"Default_AlarmTime"];
 localNotification.fireDate = currDate1;
 localNotification.alertBody = @"Alarm";
 localNotification.alertAction = @"View";
 localNotification.soundName = UILocalNotificationDefaultSoundName;
 localNotification.timeZone = [NSTimeZone defaultTimeZone];
 localNotification.repeatInterval = NSWeekdayCalendarUnit;
 [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

 // changing alert body of existing local notification


       Arr=[[UIApplication sharedApplication]scheduledLocalNotifications];
        for (int k=0;k<[Arr count];k++) 
        {
            localNotification = [Arr objectAtIndex:k];
            NSLog(@"%@",localNotification.fireDate);
            dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setTimeZone:[NSTimeZone defaultTimeZone]];
            [dateFormat setDateFormat:@"hh:mma"];
            dateString = [dateFormat stringFromDate:localNotification.fireDate];
            NSLog(@"%@",dateString); 
            currDate = [defaults objectForKey:@"Default_AlarmTime"];
            NSLog(@"%@",currDate);
            if ([currDate isEqualToString:dateString])
            {

                localNotification.alertBody = @"Haiiiiii";

            }
        }
      ---------------------------

I'm facing an issue with UILocalNotifications. my question is-- Is it possible to set the alert body of uilocalnotification after it is scheduled ??

thanks in advance.

-------------------------------------
// scheduling uilocalnotification 
localNotification = [[UILocalNotification alloc]init];
 NSDate *currDate1 = [defaults objectForKey:@"Default_AlarmTime"];
 localNotification.fireDate = currDate1;
 localNotification.alertBody = @"Alarm";
 localNotification.alertAction = @"View";
 localNotification.soundName = UILocalNotificationDefaultSoundName;
 localNotification.timeZone = [NSTimeZone defaultTimeZone];
 localNotification.repeatInterval = NSWeekdayCalendarUnit;
 [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

 // changing alert body of existing local notification


       Arr=[[UIApplication sharedApplication]scheduledLocalNotifications];
        for (int k=0;k<[Arr count];k++) 
        {
            localNotification = [Arr objectAtIndex:k];
            NSLog(@"%@",localNotification.fireDate);
            dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setTimeZone:[NSTimeZone defaultTimeZone]];
            [dateFormat setDateFormat:@"hh:mma"];
            dateString = [dateFormat stringFromDate:localNotification.fireDate];
            NSLog(@"%@",dateString); 
            currDate = [defaults objectForKey:@"Default_AlarmTime"];
            NSLog(@"%@",currDate);
            if ([currDate isEqualToString:dateString])
            {

                localNotification.alertBody = @"Haiiiiii";

            }
        }
      ---------------------------

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗笺 2025-01-15 08:29:59

据我所知,这是不可能的。要更改已安排的通知,您必须取消并完全重新安排它。

As far as I know, this is not possible. To change an already scheduled notification, you have to cancel and completely reschedule it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文