gpt4 book ai didi

iphone - 在本地通知中设置 repeatInterval

转载 作者:可可西里 更新时间:2023-11-01 05:56:29 24 4
gpt4 key购买 nike

我想将重复间隔设置为用户从日期选择器中选择的值。我的应用程序中有倒计时模式类型的日期选择器。如果用户从日期选择器中选择 4 小时 15 分钟,那么我将使用以下代码设置 firedate和闹钟。

 [NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]] 

但我希望该通知应每 4 小时 15 分钟重复一次,直到用户取消它。我做了很多研发搜索,但我无法弄清楚。到目前为止我使用的代码是:

localNotification = [[UILocalNotification alloc] init]; 
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:[pickerTimer countDownDuration]]];

if(localNotification.fireDate){

[self _showAlert:@"Time is scheduled" withTitle:@"Daily Achiever"];
}
localNotification.timeZone = [NSTimeZone systemTimeZone];


localNotification.alertBody=@"alaram";
localNotification.soundName = UILocalNotificationDefaultSoundName;
[localNotification setAlertAction:@"View"];
[localNotification setRepeatInterval:[pickerTimer countDownDuration]];

//The button's text that launches the application and is shown in the alert
// [localNotification setAlertBody:[alertBodyField text]]; //Set the message in the notification from the textField's text
//[localNotification setHasAction: YES]; //Set that pushing the button will launch the application
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1

localNotification.applicationIconBadgeNumber = 1;

localNotification.repeatInterval=NSHourCalendarUnit;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system

//[alertNotification setHidden:NO]; //Set the alertNotification to be shown showing the user that the application has registered the local notification

请帮我解决。非常感谢。

最佳答案

我已经使用下面的代码解决了这个问题:

-(void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {

testDate=notif.fireDate;
NSLog(@"Recieved Notification %@",notif);
[self playSoundWithNotification:notif];
[self _showAlert:@"Alaram" withTitle:@"Daily Achiever"];
}


-(void)_showAlert:(NSString*)pushmessage withTitle:(NSString*)title
{

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:pushmessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alertView show];

if (alertView) {
FocusViewController *fvc=[[FocusViewController alloc]initWithNibName:@"FocusViewController" bundle:nil];

[fvc insert:[NSDate dateWithTimeInterval:refTimeIntrval sinceDate:testDate]];

}}

这里的testDate和refTimeInterval是在.pch文件中声明的变量。

关于iphone - 在本地通知中设置 repeatInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14769462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com